Posts

Showing posts with the label Visual Studio

Visual Studio 2010 with TFS can't edit source code

Once in a while when I open a project in Visual Studio and get latest version of source from TFS and I go to type in a source code file it will not auto check out and will not let me type anything.  The quickest way I have discovered to fix this is to click on another source code tab(or open another source code file if there is only one tab available) then go back to the original source code and you should be able to start typing.

How to include a file in Visual Studio MSTest

Once in a while I add a xml file to be processed as part of an integration test in a MSTest project in Visual Studio but the file is missing when the test is run.  Here are the steps to get the file to show up when the test is run: Add file to MSTest project and set it to copy always. Go to Test -> Edit test settings -> Local(local.testsettings) Select Deployment Check “Enable deployment” Add DeploymentItem(“nameoffile”) attribute to test RESTART Visual Studio! Remember to do step 6 because it will only begin working after Visual Studio is restarted.

VS 2008 Next Error keyboard shortcut

When I’m refactoring some code if there is an interface change I usually make the interface change first and then fix all the error’s that come up.  Using the mouse to go to the errors window and double click on the next error can get tedious so I did some research to figure out a better way and found there is a keyboard short cut "ctrl-shift-F12" in VS 2008 that will take you to the next error. For more information on keyboard short cuts check this out: http://www.mobydisk.com/softdev/techinfo/dotnetkeyboard.html

Speed Improvement by avoiding exceptions

Image
I learned a neat thing.  If you press ctrl-alt-e in Visual Studio you bring up this dialog: Then check the Thrown checkbox for "Common Language Runtime Exceptions" like this: Then run the project in debug mode and if an exception occurs the run will break at that point in the code and you can examine what happened.  This is great for finding uncaught exceptions and improper use of exceptions like this:                 Try                     If c.Contains( "somestring" ) Then Stop                 Catch ex As NullReferenceException                 End Try One should never do this because it is extremely inefficient.  Exceptions are costly and should always be avoided if possible.  In this case we can avoid this exception by checking c for nothing, like so:     ...

VS 2008 with Team Explorer Unit Test TestContext Error

After upgrading from VS Team System 2005 to VS 2008 with Team Explorer I had a TestContext error when trying to run a unit test. After some research I found that you have to change the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll from v8 to v9.

How to add a Solution Folder to an existing Solution Folder with VS 2005 Guidance Automation

If you have an EnvDTE.Project reference to an existing Solution Folder you can add a solution folder like so: C# ((EnvDTE80. SolutionFolder )root.Object).AddSolutionFolder( "solutionFolder" ); or VB DirectCast(root.[Object], EnvDTE80.SolutionFolder).AddSolutionFolder("solutionFolder") where "root" is the EnvDTE.Project reference to the existing Solution Folder.

How to search and replace a return character in Visual Studio

Every once in a while I need to search and replace a character with a "return" character and I forget how to do it and have to search online.  This latest search I found the answer here(it was there in 2008, but it is there longer): http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=112303 In your search dialog turn on regular expressions and use  "\x0d\x0a" for the "return" character.

VS 2005 ASP.NET 2.0 DropDownList ToolTip in IE7

You can set the title attribute on the drop down list items to have ToolTip popups on your DropDownList items. This does not work in IE6 but works in IE7. For example you can do it right in the aspx like this: < asp : DropDownList ID ="DropDownList1" runat ="server">             < asp : ListItem title ="Choice 1 ToolTip" Value ="1"> Choice 1 asp : ListItem >             < asp : ListItem title ="Choice 2 ToolTip" Value ="2"> Choice 2 asp : ListItem > asp : DropDownList > Visual Studio will say that “Attribute 'title' is not a valid attribute of element 'ListItem'.” but it will run fine. Or you can do it in the code behind like this: Protected Sub DropDownList1_DataBound( ByVal sender As Object , ByVal e As System.EventArgs) Handles DropDownList1.DataBound Dim toolTip As String = string .Empty For Each item As ...

NArrange - organize your code effortlessly

Image
The second thing I do( this is the first ) with a new install of Visual Studio is I head over to  http://www.narrange.net/download.aspx  and download the latest version of NArrange.  NArrange is an open source .NET code organizer/formatter/beautifier. After downloading and installing(and noting the folder where the exe is installed) the NArrange setup.msi, I go into my new install of Visual Studio and click on Tools and select External Tools . This opens the External Tools dialogue.  Click Add  and in the Title  field I put "NArrange" and beside the Command  field I click the ... (browse) button and go to the folder where I installed NArrange and select the narrange-console.exe file.  For Arguments  I like to only do one file at a time as I'm working so I set it to $(ItemFileName)$(ItemExt) /b and the Initial directory  to $(ItemDir).  The /b causes a back up of the file before NArrange makes it's changes, thi...

Add a field to a Visual Studio 2005 Report Services Report

Image
In the Datasets area right-click on a DataSource and select Add . Enter in the Name of the new field and the Database field or Calculated field . Then we need to update the tie between the Dataset and SQL Server by clicking on the Data tab and selecting our Dataset in the dropdown and updating the query.

Refactoring with CodeRush Xpress

Image
One of the first things I do with a new install of Visual Studio(VS) is I head over to DevExpress and download/install CodeRush Xpress . CodeRush Xpress is a free refactoring tool from DevExpress for VS 2010 or older(They stopped offering the free version for VS 2012 or newer so now it looks like the first thing I'll be doing with a new install of Visual Studio is beg my boss for a CodeRush license). If you are not familiar with refactoring and you are interested in being a better coder you should read Martin Fowler's book: Refactoring: Improving the Design of Existing Code (Addison-Wesley Object Technology Series). In it the authors Martin Fowler , Kent Beck , John Brant , William Opdyke and Don Roberts give very practical advice on improving the design of code. Along with improving the design of code, refactoring can improve the readability of code.  My favorite refactoring pattern for this is Extract Method(EM) . When you come across a really long method or find th...