Blog - Title

Visual Studio 2013 Current Status

  • The Ultimate Visual Studio Tips and Tricks Blog

    Collapsing Your Code with Outlining


    Keyboard:  CTRL + M, CTRL + M
    Menu:  Edit -> Outlining -> Toggle Outlining Expansion
    Command:  Edit.ToggleOutliningExpansion
    Versions:  2008,2010
    Published:  3/15/2010
    Code:  vstipEdit0029


    By default, Outlining is enabled in Visual Studio.  It's the line you see with the boxes to indicate the status of the area (collapsed or expanded):



    You can collapse areas of code to get them out of your way so you can focus on other areas.  There are four ways to do it:

    1. Click on the minus sign to collapse an area of code:


      NOTE:  In VS2010 it now highlights the area that will be collapsed as seen here.  A very cool feature.  If you don't like the highlighting color you can go to Tools -> Options -> Environment -> Fonts and Colors -> Collapsible Region to change it.

    2. VS2010 ONLY:  Click ANYWHERE on the vertical line in the highlighted region.  In other words, you can now collapse a region from anywhere in that region:
    3. Click anywhere in the area to be collapsed and hit CTRL + M, CTRL + M
    4. Click anywhere in the area to be collapsed and go to Edit -> Outlining -> Toggle Outlining Expansion on the Menu Bar


    Once collapsed, the code area will look like this:


  • The Ultimate Visual Studio Tips and Tricks Blog

    Vista Activation


    If you haven't come across this yet you will at some point.  There is a known issue with Vista and activation.  You can get the details for common errors at this KB article, but the steps are pretty straightforward:

    1) Go to Control Panel...System and Maintainence...System

    2) Scroll to the bottom of the screen

    3) Click on Change Product Key

    4) Type in your key

    5) Click Next and follow the rest of the steps in the wizard


    That's it!   Soon you'll be enjoying Vista and be activated :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013 Preview: Code Map Debugger Integration


    5-16-2012 12-48-10 PM



    The original Code Map was introduced in the product with Visual Studio 2012 Update 1. You need to read my original post before moving on:


    My assessment at the time was that it was a good feature but had poor performance and didn’t really add much value relative to Dependency Graphs. With debugger integration however Code Maps have definitely come into their own and the performance is very good.


    Note: Code Map Debugger Integration is a feature in the Ultimate edition of Visual Studio.




    Code Map Debugger Integration

    Assuming you have a handle on Code Maps now let’s see how the debugger integration works. First, I’ll take the TailSpin Toys sample code and set a breakpoint within the code base (ShoppingCart.cs, line 61):

    5-16-2012 12-04-13 PM



    I’ll press F5 and add an item to my cart to trigger the debugger:

    5-16-2012 12-07-12 PM



    Ordinarily, we would step though the code and hope we remember how we got to a particular place. Those days are gone! Now we can turn on the Code Map feature while debugging:

    5-16-2012 12-12-27 PM



    You can also find this on the Menu Bar at Debug | Show Call Stack on Code Map:

    5-16-2012 12-13-37 PM



    You will see a Code Map in sync with the debugger at this point. You can create Code Maps in C#, VB, C++, JavaScript currently. Once activated all future debugging sessions will include a Code Map until you turn this feature off:

    5-16-2012 12-17-38 PM



    If we take a closer look at the current map, we can see that it shows how we arrived at the current call (the squares above the last AddItem call) and our current location (yellow arrow). Although the current location indicator is partially covering it, you can also see the breakpoint indicator:

    5-16-2012 12-27-35 PM



    Stepping through the code we see the map keeps updating so we don’t have to keep the path in our heads:

    5-16-2012 12-29-19 PM



    The Code Map will continue to update for our debugging session showing where we have been and where we currently are in the call stack:

    5-16-2012 12-35-58 PM



    The graphs can get quite large:

    5-16-2012 12-40-46 PM



    For this reason it’s important to use the map tools at your disposal. The context menu items when you Right Click any node are a great example of common tools:

    5-16-2012 12-45-23 PM



    You can Double Click any node to view the code from that location in the stack. A green arrow will indicate your current position:

    5-16-2012 12-54-27 PM



    If you happen to choose a node that isn’t part of the current active call stack then you will get a slightly different indicator:

    5-16-2012 12-57-41 PM



    When you stop debugging the Code Map will be preserved so you can save it if desired and keep a map of the code base you just went through. I think this is an exceptional addition to the debugging experience!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Using Solution Folders


    Menu:  Project -> Add New Solution Folder; [Right-Click Solution] -> Add -> New Solution Folder
    Command:  Project.AddNewSolutionFolder
    Versions:  2008,2010
    Published:  3/27/2010
    Code:  vstipProj0009


    Did you know there are special folders to help you organize large solutions?  There is!  They are called, appropriately enough, Solution Folders.  To create one just Right-Click on your solution (or go to Project -> Add New Solution Folder) and you will see this in Solution Explorer:



    Simply give the folder a name and you are good to go.  But so what?  I mean, what can you actually DO with these things?  Here is a list of stuff you can do:

    • Move or add projects to them. Solution Folders can be nested to create greater organizational structure.

    • Add, delete, or rename Solution Folders at any time, if the organizational requirements of the solution change.

    • Unload all projects in a Solution Folder to make them temporarily unavailable for building.

    • Collapse or hide entire Solution Folders so that you can work more easily in Solution Explorer. Hidden projects are built when you build the solution. 

    • Build or rebuild all the projects. The projects are built in the order specified by the project dependencies.


    Solution Folders are an organizational tool in Solution Explorer; corresponding Windows folders are not created.  Microsoft recommends that you organize your projects on disk in the same way that you organize them in the solution.  But that is your call :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013: Zooming In and Out of Text in the Editor


    This week I thought we would focus on some fun quickies that have been in Visual Studio since at least VS2010. The first one we will look at is simply zooming your text in the editor. The concept is really simple. For example, you may want to go from this:

    5-16-2012 12-06-52 PM


    To this:

    5-16-2012 12-08-13 PM


    Being able to zoom in and out is useful if you have trouble seeing or you are doing extreme programming or any situation where making text more readable is necessary. One other thing to keep in mind is that zooming is a per tab activity so zooming in one tab does not set the same zoom level in other tabs. Each tab has it's own zoom level.



    Mouse Wheel

    You can zoom in and out of text using the wheel on your mouse. Just hold down CTRL+Mouse Wheel and you can instantly zoom in and out of text in the editor.


    Most people discover this accidentally. If this annoys you then you can see if there is an update to the Disable Mouse Wheel Zoom extension:


    At the time of writing there isn’t a version that works with VS2013 but that could change.



    Combo Box

    You can go “old school” and use the combo box at the bottom left of the IDE:

    5-16-2012 12-16-30 PM




    If you prefer to use the keyboard, you can always use CTRL+SHIFT+>[Greater Than] and CTRL+SHIFT+<[Less Than].

  • The Ultimate Visual Studio Tips and Tricks Blog

    Automatically Check for Updates to Visual Studio 11


    There is an update to Visual Studio 11 that came out in early April that is available.  You can find the details here:


    If you haven’t been playing with Visual Studio 11 yet, I strongly encourage you to get it today.  You can download it from here:


    When you DO have it one of the first things you should do is turn on automatic checking for updates to extensions found at Tools | Options | Environment | Extension Manager:



    Not only will this make sure you are notified about the latest and greatest version of your favorite extensions but it will also enable notification of updates to Visual Studio!  We are now pushing updates to the IDE as extension-like elements. When you enable this feature, every time you start Visual Studio you will see a message whenever there is an update to Visual Studio that looks like this:



    You can click on the bubble or, to get to updates manually, go to Tools | Options | Extension Manager | Updates | Product Updates:



    You will see the update(s) available and can then click on the Update button for the items you want. In this case, when I clicked on update for the April 2012 fix for VS11, I received the download dialog:



    Selecting Run began the installation process:



    It finished smoothly and Visual Studio was updated easily.


    Go out there and update your version of Visual Studio 11 if you haven’t done it already so you can get the most up-to-date goodies!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Calculating Mean, Median and Mode with SQL Server




    I LOVE statistics and was recently asked about calculating the mean, median, and mode using SQL Server.  I found this great article by George Mastros that shows you how:

  • The Ultimate Visual Studio Tips and Tricks Blog

    Creating, Configuring, and Consuming a WCF Service in IIS 7


    After much delay, here are the goods :)


    The goal here is to show how to create a basic WCF service that can be hosted in IIS7 and will kick over to other protocols using Windows Activation Service (WAS) as needed.  Your choice of language doesn't matter for this one and I will show code for C# and VB.  And awaaaaaaay we go...



    1. Start up Visual Studio by running it as Administrator

    2. Begin creating a new Web Site

    3. Feel free to pick your language of choice, for this demo I will call the services CoolServiceCS and CoolServiceVB respectively

    4. Press F5 to build and run the application just to make sure all is well so far, you will get the obligatory error for debugging, just click OK:

    5. You should ultimately see a web page that has something like this:

    6. Close the service web page and let's see if IIS7 is aware of this service
    7. Go to the IIS Manager


    8. Expand the tree and, under "Default Web Site", you should see your service.

    9. Okay!  So far everything seems to be going well.  Now let's take a quick peek at the service in Visual Studio to verify that it is, in fact, using HTTP to communicate.
    10. There are a couple of ways we can do this:  One way is to just open up Web.config and scroll to the <services> element:

    11. Another way is to right-click on your Web.config and choose "Edit WCF Configuration..."
      SPECIAL NOTE:  There seems to be a "feature" that makes this not show up initially.  This is usually "fixed" by simply going to Tools...WCF Service Configuration Editor
      The funny thing is you don't appear to have to actually use this tool just open it and close it then you can right-click Web.config to get the editor option.  Weird.

    12. If you expand the Service area and look at the Endpoints, you can see that wsHTTPBinding is used.  Once you have verified, close this dialog box.

    13. The only thing I wish here is that the endpoints would be "automagically" named for us (we could always change the names) but, sadly, that is not the case.
    14. At this point we have created our service, run it, verified it is in IIS, and verified it uses wsHTTPBinding.  Now we need to create a client to consume the service.
    15. In Visual Studio, right-click on your Solution and choose Add New Project...

    16. Let's use a Console Application for our client this time around.  Make sure to use your language of choice.

    17. Call the application "CoolServiceClientVB" or "CoolServiceClientCS" as appropriate then click on OK.

    18. Set the new project as the Startup Project.  

    19. Now we need to right-click on the project and choose Add Service Reference...

    20. The new service dialog is very cool and will find services in your solution if you just click on Discover --go for it! 

    21. Leave all other settings as they are and click on OK.  You should see your reference in Solution Explorer.

    22. Now let's crank a little code to actually use this service (finally!) heheh...
    23. Open up Module1.vb or Program.cs and put the following code in:

    24. Sub Main()
             Dim myService As New ServiceReference1.ServiceClient()


         End Sub


      static void Main(string[] args)
                  ServiceReference1.ServiceClient myService =
                      new CoolServiceClientCS.ServiceReference1.ServiceClient();



    25. This should look pretty straightforward.  We are calling one of the sample operations that are available with our WCF Service and then use ReadKey() to pause when we run the app.
    26. Press F5 to run this sucker and you should get this:

    27. Press any key to continue.
    28. So we have a client and we have a service and we are all having a group hug.  Now what?  Well, now let's configure this puppy to use other protocols besides HTTP.  For this run, we will use TCP and Named Pipes.
    29. First, we have to configure Windows Process Activation Service (WAS) settings.  To learn more about WAS, go here:
    30. Assuming you're running Vista, we have to tell WAS that non-HTTP protocols can be used for activation.  If we were not using IIS to host this service we would also have had to tell it that HTTP activation is possible but fortunately IIS handles those details for us.  For more info on what we are doing here, you can check out this area
    31. Go to Control Panel

    32. Choose Programs

    33. Now select Turn Windows Features On or Off

    34. Go to the Microsoft .NET Framework 3.0 area and check the WCF Non-HTTP Activation.  NOTE:  Since this is my play machine, I also turned on WCF HTTP Activation as well but you don't have to unless you need it.

    35. Click on OK; It may take a minute to install the needed files so be patient.  Go grab a drink or something, go on, you deserve it :)
    36. Next we have to configure the the web site to be bound to a TCP port for our activation to work.
    37. Open a command prompt with administrative privileges by right-clicking on the command prompt icon and choosing Run as Administrator

    38. Copy and paste the following command into the command prompt area and press Enter

      %windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']
    39. The result should look similar to the following:

    40. Now the Default Web Site is bound to TCP but we still need to allow TCP for our applicationCopy and paste the following into the command prompt area and press Enter:

      %windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/CoolServiceVB" /enabledProtocols:http,net.tcp

      %windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/CoolServiceCS" /enabledProtocols:http,net.tcp
    41. You should see something like this:

    42. Okay, the hard part is done.  We now have the Web Site and the application within the site configured for TCP.  We just need to tell the service to use TCP and then have the client use TCP to talk to the service.  Here we go!
    43. To configure the service, go to Visual Studio and Solution Explorer.  Now let's go to our service and right-click on Web.config to edit the WCF Configuration.  You may have to do that stupid Tools...WCF Service Configuration Editor workaround to get the context menu item to show up.  You may wonder why I just don't have you edit the XML directly and the answer is simple:  I'm all about easy and think that this way is easier for folks.

    44. We need to make sure the service knows it can use TCP by creating a new endpoint.  Currently the only usable endpoint for communicating is HTTP but we are going to change that by right-clicking on endpoints under the Service and adding a new service endpoint.

    45. Enter myTcpGoodness for the Name, choose netTcpBinding for the Binding, and enter IService for the Contract as seen here:

    46. We also need to identify the BaseAddress for getting to our service.  Go to the Host area in the current dialog.

    47. Under Base Address, click on New... and type in the following for the address then press enter:


    48. You should see something like this in the BaseAddress area:

    49. Close the configuration dialog and you should be prompted to save changes.  Click Yes.

    50. Let's make sure there are no errors.  Build the service by right-clicking on it and choosing Build Web Site.
    51. WOW!  We are on step 50 now.  Does it feel like your brain is going to explode like in the movie "Scanners"?  Just stay with me, we are almost done.
    52. At this point we could start configuring the client but I really like to run the service one last time to make sure there are no issues.  So this step is optional but suggested just to make sure everything is good with the service:  (1) Right-click on the Service.svc file and set it as the Start Page.  Right-click on the service project and choose Set as Startup Project.  Press F5 to run the application.  You should see the test page for the service.  If you do then all is well, if not go back and fix any issues.  Make sure to close the web page when you are done here and set the client application as the Start Up Project again.

    53. Okay now on to the client.  Since we have updated the service we need to update the Service Reference on the client.  This is easily done.  Simply right-click on ServiceReference1 and choose Update Service Reference.

    54. You should see this dialog flash by:

    55. We are almost done.  Now we just have to tell the client what protocol to use based on the binding name.  Remember when you set the Name of the TCP Binding to myTcpGoodness?  Well you did that to make this step easier for us.  Go to Module1.vb or Program.cs to see the code for your client application.
    56. Now we will pass the name of the binding to use in the constructor so that the client uses the protocol we want.  Change the code for creating an instance of the service to this:

      Dim myService As New ServiceReference1.ServiceClient("myTcpGoodness")

    57. ServiceReference1.ServiceClient myService =
                      new CoolServiceClientCS.ServiceReference1.ServiceClient("myTcpGoodness");

    58. Now just run your client application and you should see the predictable result.

    59. At this point you are probably asking if it is REALLY using TCP.  It's easy enough to test.  From your command prompt type in the following:

      net stop w3svc
    60. You should see this:

    61. You have stopped IIS and killed HTTP as an option for communicating to our service.  Now run the client application again.  Does it work?  Then you are in business!
    62. We are done but if you want you can add net.pipe to be used just like you did with net.tcp and see if it works.  Play with it and enjoy!  Oh yeah, you might want to type in "net start w3svc" from the command prompt to get IIS running again.  :P
  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Code Clone Analysis


    In my travels across the country, with my fellow Evangelist, Clint Edmonson, talking about Visual Studio we often come across great stories to tell. One of our favorite true stories is of a customer that had a web application running very slow. We ran code metrics against it and, sure enough, the Page_Load event had 9,000 lines of code in it.


    Naturally we were curious so we opened it up to see that it was basically the same if statement copied over and over. Apparently they needed to find out who was coming into the website in order to show customized content and the solution they came up with was this massive set of statements.


    For better or worse we have all had code that gets copied throughout our solutions. Until now there was no tool to tell us there were copies and, instead, we had to rely on other metrics to hopefully reveal any code smells that lead us to duplicates. Now, however, we have the new Code Clone Detection (aka Code Clone Analysis) feature.


    According to the documentation:

    Code clones are separate fragments of code that are very similar. They are a common phenomenon in an application that has been under development for some time. Clones make it hard to change your application because you have to find and update more than one fragment. Visual Studio can help you find code clones so that you can refactor them.”



    Specific Clones

    You can find clones of specific code by selecting the segment you are interested then right click on the selection to choose Find Matching Clones in Solution from the context menu:



    Visual Studio will search for code clones and produce the result in the new Code Clone Search Results window:



    The original line of code is put in a group on its own and then all the matches are put into a different group. You can expand the groups to see the specific locations of the matches:



    Also, you can double click on any entry in the list to go to the selection in your code file:




    Solution Clones

    Besides looking for specific clones you can also look for code clones for the entire solution. To use this feature go to Analyze | Analyze Solution for Code Clones:



    This creates a result set for the entire solution:



    By default it groups and sorts the results by the strength of the match. Exact matches come first then those matches that may be close but not exact come next and so on. The terms you may see are Exact, Strong, Medium, and Weak.



    Reviewing Matches

    Once you have the result set, there are a couple of ways you can compare them against each other.


    Comparison Tools

    If you have a comparison tool configured you can Right-click on any item and select Compare from the shortcut menu:



    You would know if you have this feature available by going to Tools | Options | Source Control | Team Foundation Server and click on Configure User Tools.



    Manual Comparison

    If you don’t have a comparison tool you can do manual comparisons between two entries in the list. If the clones are in different files then you can just double-click each entry and it will open the file as well as highlight the entry that is duplicated as mentioned earlier.


    What Is Found

    You are probably curious as to what is found by this tool. The heuristics for finding clones will find duplicates even if the following changes have happened:

    · Renamed identifiers

    · Insert and delete statements added

    · Rearranged statements



    What Is Not Found

    There are some rules for what is not found as well. I have taken this list from the documentation pretty much verbatim.

    · Type declarations are not compared. For example, if you have two classes with very similar sets of field declarations, they will not be reported as clones. Only statements in methods and property definitions are compared.

    · Analyze Solution for Code Clones will not find clones that are less than 10 statements long. However, you can apply Find matching clones in solution to shorter fragments.

    · Fragments with more than 40% changed tokens.

    · If a project contains a .codeclonesettings file, code elements that are defined in that project will not be searched if they are named in the Exclusions section of the .codeclonesettings file.

    · Some kinds of generated code are excluded:

    · *.designer.cs, *.designer.vb

    · InitializeComponent methods



    Code Clone Settings and Exclusions

    A settings file is available to configure this feature at the project level. Currently we have only announced the ability to do exclusions in the file but there will most likely be other elements that are added later on. The file is just XML with a .CODECLONESETTINGS extension. The only requirement for use is that the file exists in the top level directory of the project.


    The base elements consist of a CodeCloneSettings element with an Exclusions child:



    Within the Exclusions element you can have the following children:


    This element is used to indicate files that should be excluded from analysis. Path names can be absolute or relative and you can use wildcards as well. So, for example, to ignore all the C# text template files that have been put in their own directory (called MyTextTemplates) you might have the following:



    <Namespace>, <Type>, and <FunctionName>

    You can also exclude namespaces, types, and functions. Just like files these items can use absolute names or names with wildcards in them. Here is an example of what it might look like:




    Exclusion File Example

    In the Tailspin Toys sample there is some generated code in the TailSpin.SimpleSqlRepository project that is the bulk of the duplications:



    When I run code analysis, this is the result:



    Code clone analysis doesn’t automatically know to ignore text templates so I would create an XML file called TailSpinRepository.codeclonesettings and insert an entry like this:



    Now if I run clone analysis again here is what I get:



    As you can see the results are significantly less than the first time the analysis ran. It’s common to create several exclusions in different projects to weed out noise in the analysis results.




    Code Clone Detection is a great new tool to add to your arsenal for improving code quality. Combined with Code Analysis and Code Metrics, this will help quickly find potential issues.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Preview Tab



    Preview Tab Overview

    We all explore code and need to move quickly between files when examining code to get familiar with it or debugging or [insert file browsing scenario here]. In prior versions of Visual Studio you had to open a file to look at the contents which often resulted in many open files (tabs) when you were done. The Preview Tab eliminates the need to open files when browsing code. Most likely you’ll first encounter the Preview Tab when you are looking at files with Solution Explorer. When you click on a supported file type, you will see the contents of that file in the new preview tab (to the far right in the tab well):



    If you click anywhere inside the file the tab will go from grey to purple to distinguish it from regular (blue) tabs:



    Again, the point of the preview tab is to let you view the contents of a file without actually opening up a new tab in the tab well. As you look at different files the preview tab only shows the contents of the file you are currently on. This keeps the environment from getting cluttered with open tabs and allows you to focus on only those files that are interesting to you. Solution Explorer isn’t the only place you can use the preview feature. It turns up in several situations where you might need to look at file content. For example, when using Find in Files (CTRL + SHIFT + F) to locate information you will see the preview tab:




    Promoting Previews

    At some point you may decide to promote the preview to an opened tab in the Tab Well so you can do additional work on the file or just keep it around for other purposes. There are a few ways you can make this happen.


    Click the Keep Open button

    Probably the least useful and and least likely technique you will use is to click on the tiny Keep Open button on the Preview Tab.  It’s not only useless it’s actually kind of annoying for some reason I can’t identify:



    Double Click the File

    The most likely approach is you will just double click the file in Solution Explorer or whatever results dialog you happen to be in.


    Press CTRL + ALT + HOME

    With the cursor inside the file (the tab is purple), just press CTRL + ALT + HOME to open a tab for the file you are currently viewing.


    Change the File

    While previewing a file, if you make any change to the file it will automatically be promoted to an open tab so that you can make additional changes and do any other actions you need to perform.


    Click the Preview Selected Items button

    Another button is useless and a waste of space on the Solution Explorer toolbar is the Preview Selected Items button.  You can click it to preview the current file and its only use that I can find is if you turn off single clicking a file to preview it (see below).  Also the tooltip would lead you to believe that you can select multiple files and preview them.  Nope.  Doesn’t work.  Don’t waste your time with this button.




    Turning Preview Off

    To see the options you have for using the preview feature, just type preview in Quick Launch (CTRL + Q) and click Environment -> Tabs and Windows:



    This will take you to Tools | Options | Environment | Tabs and Windows:




    To turn off the preview feature (NOT suggested unless you are having performance issues with it) uncheck the Allow New Files to be Opened in the Preview Tab option. Also notice you can decide if a single click open the files in for preview in Solution Explorer and Find dialogs. For Solution Explorer you can use ALT to prevent a file from being previewed when you click on it. While I see the value in using ALT to prevent preview from happening. I haven’t yet found any reason for turning off the single-click option as it, in effect, forces you to use the Preview Selected Items button which is a lot of extra work and kind of defeats the purpose of the feature.




    The Preview Tab is one of my top two favorite features in Visual Studio 2012 (the other one being project round-tripping).  You definitely want to leverage this feature to make your life easier.

Page 5 of 135 (1,345 items) «34567»