Blog - Title

Visual Studio 2013 Current Status

  • The Ultimate Visual Studio Tips and Tricks Blog

    Searching Your Favorites in Vista

    • 1 Comments

    Okay so I figured out how to put the .url extension in the advanced indexing options so you can search your favorites only to find out that, hey, you don't have to do all that crap.  If you want to search your favs in IE you just type in a part of the name and it shows up.  Talk about a DUH moment.  So if you haven't played with it much, I suggest you try out the seriously cool search features in Vista.  As for me, I'm off to the Windows Help site to brush up on my searching...

    Searching Favorites in Vista

  • The Ultimate Visual Studio Tips and Tricks Blog

    Comment and Uncomment Code

    • 9 Comments

    Keyboard:  CTRL + K, CTRL + C (comment); CTRL + K, CTRL + U (uncomment)
    Menu:  Edit -> Advanced -> Comment Selection; Edit -> Advanced -> Uncomment Selection
    Command:  Edit.CommentSelection; Edit.UncommentSelection
    Versions:  2008,2010
    Published:  4/13/2010
    Code:  vstipEdit0047

     

    Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!

     

    Sometimes it's the simple stuff we forget about.  So I present to you the classic Comment and Uncomment Selection.  Naturally, you have the Comment and Uncomment buttons:

    image

     

    And, of course, we have the Menu items:

    image

     

    But it's the keyboard shortcuts that really rock!  These will, predictably, comment or uncomment lines of code for you.  So, let's say you have some code you want commented out.  Just select it:

    image

     

    Then press CTRL + K, CTRL + C (in this example):

    image

     

    Voila!  It's commented out.  Okay, great, but what if you don't want to use the mouse?  No problem!  Just hold ALT + SHIFT + [UP or DOWN ARROW] to do a vertical selection (NOTE:  In VS2008 you have to go right or left one character before you can go up or down for vertical selection):

    image

     

    Then press CTRL + K, CTRL + U (in this example):

    image

     

    And there you go!  Comment and Uncomment actions anytime you want!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Turn on Line Numbers

    • 19 Comments

    Menu:  Tools -> Options -> Text Editor -> All Languages -> General -> Display
    Versions:  2008,2010
    Published:  3/7/2010
    Code:  vstipEdit0025

     

    Line numbers are not on by default.  To turn on line numbers just go to Tools -> Options -> Text Editor -> All Languages -> General -> Display and check Line numbers:

    image

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 Color Theme Choices

    • 2 Comments

     

    The other day I had a customer complain about not liking the Light and Dark color themes that come out of the box with VS2012.  I’m always up for more choices with color schemes so thought I would make sure you all knew about the options for color schemes.  There are actually many, many ways you “could” change your fonts and colors but I’ll show you what I consider to be the top two methods in no particular order.

     

    Visual Studio Color Theme Editor

    http://visualstudiogallery.msdn.microsoft.com/366ad100-0003-4c9a-81a8-337d4e7ace05

    image

     

    One of the more popular extensions we created after VS2012 launched was the Color Theme Editor.  it comes with pre-set themes as well as the ability to customize your themes any way you see fit.  Since it is an extension, you can obtain this feature quickly by following the link to the extension and then clicking the Download link:

    image

     

    Next just click the Open button to install the extension:

    SNAGHTML1819303

     

    Now just follow the on-screen instructions to finish the installation.

     

     

    Using the Theme Editor

    To use the editor you can simply choose a theme by going to Tools | Change Color Theme and selecting a pre-set theme:

    image

     

    Notice that just below Change Color Theme is Customize Colors which allows you to create custom color sets as well.  It’s not very intuitive so let me walk you though a little bit of it.  First you have to pick an existing theme to copy from and then give the custom theme a name and click the Create button:

    image

     

    Now you will be presented with a dizzying array of options you can modify to create a custom look and feel to your environment:

    image

     

     

    DANGER:  It appears that the Color Theme Editor doesn’t like it when you import settings through the IDE and will use the imported settings instead of the expected settings when changing themes.  My advice is to create a custom theme and set it as the current theme then import settings as desired (shown below) so you don’t get messed up themes.

     

     

     

    StudioStyles

    If you haven’t been to http://studiostyl.es/ yet then you have missed out on some seriously cool styles:

    image

     

     

     

    Getting a Style

    Let me walk you though how to use one of these styles.  First, you need to find a style you like.  I suggest you pick from the All-Time Favourites section.  My personal favorite for quite some time has been WekeRoad Ink:

    image

     

     

    Once you select the style you want then select the proper version of Visual Studio and click the download button:

    image

     

    This will give you a .VSSETTINGS file with just font and color information that you can import into the IDE by going to Tools | Import and Export Settings:

    image

     

     

    Choose Import Selected Environment Settings then click the Next button:

    SNAGHTML1a7fb18

     

     

    You should absolutely make sure you BACK UP YOUR CURRENT SETTINGS then click Next:

    SNAGHTML1a9ec4a

     

     

    Use the Browse button to find the .VSSETTINGS file you found then click Next:

    SNAGHTML1adc2ca

     

     

    Click the Finish button on the current screen:

    SNAGHTML1ae836a

     

     

    Choose Close on the last screen and you should have your new color theme:

    image

     

     

    Undoing Any Changes

    You can import your previous settings to change the theme back to any colors you had before.  For more information see my previous post here:

    http://blogs.msdn.com/b/zainnab/archive/2010/07/15/importing-or-changing-your-environment-settings-vstipenv0022.aspx

  • The Ultimate Visual Studio Tips and Tricks Blog

    Calling a PowerShell Script From Your .NET Code

    • 18 Comments

     

    Well, Mike F. reminded me to write this article on 5/29 and I am FINALLY getting around to doing it.  Also wanted to give a shout out to Max T. who provided some inspiration on this one as well.  For the code, I borrow very heavily from the article written by Jean-Paul Mikkers found at: 

    http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

     

    NOTE:  There is an async version of his code that he does as a follow up.  I don't use it because I want to remove extra code noise to focus on the act of calling the script itself.  If you want to take a stab at the async version (and there are LOTS of good reasons to do so) then you can go here:

    http://www.codeproject.com/KB/threads/AsyncPowerShell.aspx 

     

    So, on to the goodness!

     

    First, you need to make sure you have Visual Studio (any version) installed and have PowerShell installed.  You can get PowerShell from here:

    http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

     

    You will also need to do this (WARNING:  MAJOR SECURITY ISSUE HERE AND THIS IS JUST FOR TESTING SO DON'T DO THIS ON PRODUCTION MACHINES):

    http://www.cubiczone.com/Articles/tabid/65/EntryID/17/Default.aspx

     

     

     

    1.   Now, let's crank out a simple PoweShell script that we are interested in calling.  We will call a simple script that takes a couple of numbers and returns the sum of those numbers.  This may seem overly simplistic but it is an easy way to demonstrate a complete round-trip between our app and the script without getting bogged down in extra BS that comes with a fancier script.  I'll call the script AddItUp.ps1 and it is included in the source code download, just put it anywhere you can get to easily.  Feel free to dig into the guts of it later on but for now just assume it does what we need it to do. 

     

    Here is the code for the script if you just want to make your own real quick:

     

    # begin

    function AddStuff($x,$y)
    {
       $x + $y
    }

     

    AddStuff 6 5

    # end

     

    NOTE:  Some inspiration and just a cool site for scripts came from http://www.powershellpro.com just as an fyi

     

     

     

    2.  Test the script by opening PowerShell and navigating to the directory where it is and typing what you see in the graphic, you should get the expected result.

    image

     

     

     

     

    3.  Okay!  We have a script that works but now what?  Well we have to call that puppy from our code so let's create a project and get ready to make our magic happen.  Crank out a new Windows App for us to use.  Call the Project CallMeCS or CallMeVB depending on your language.

     

     

    image

     

     

     

     

    4.  For the interface, just gimme a button and a label.  Resize the form a bit so we don't have wasted space.  Real simple stuff...

     

    image

     

     

     

    5.  Double-click on the button to go into our code.

     

    C#:

    image

     

    VB:

    image

     

     

     

    6.  Now we need to add an assembly that is one of a set we got with our install of PowerShell.  You can find these assemblies at C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0

     

    image

     

    7.  Right-click on your project and choose Add Reference...

     

    image

     

     

    8.  Select the Browse Tab and locate these assemblies then add a reference to the System.Management.Automation.dll

    NOTE:  If you want to dig deeper into the contents of this namespace, you can check it out here:  http://msdn.microsoft.com/en-us/library/system.management.automation(VS.85).aspx

     

    image

     

     

    9.  Now that we have our reference we need to add some using/imports statements to make getting to the classes we want to use easier.  Make sure to put these at the top of your code page outside any other code. 

     

    C#:

    using System.Collections.ObjectModel;
    using System.Management.Automation;
    using System.Management.Automation.Runspaces;
    using System.IO;

     

    VB:

    Imports System.Collections.ObjectModel
    Imports System.Management.Automation
    Imports System.Management.Automation.Runspaces
    Imports System.Text
    Imports System.IO

     

     

    10.  Okay, this next part is a little funkier.  While I liked the code that Mikkers had, I wanted to be able to load up a file from my file system and use it instead of just putting code into a textbox.  That created some VERY interesting new challenges but the end result worked out well.  So, to that end, we will create two helper methods:  RunScript and LoadScript.  RunScript is the code essentially unchanged from Mikkers' article and LoadScript is my helper function that will load the contents of a script file and return a string.

     

     

    11.  Let's begin with the RunScript method.  We will add this method to the Form1 class to make our life easier. 

     

    C#:

    private string RunScript(string scriptText)
       {
           // create Powershell runspace
           Runspace runspace = RunspaceFactory.CreateRunspace();

           // open it
           runspace.Open();

           // create a pipeline and feed it the script text
           Pipeline pipeline = runspace.CreatePipeline();
           pipeline.Commands.AddScript(scriptText);

           // add an extra command to transform the script output objects into nicely formatted strings
           // remove this line to get the actual objects that the script returns. For example, the script
           // "Get-Process" returns a collection of System.Diagnostics.Process instances.
           pipeline.Commands.Add("Out-String");

           // execute the script
           Collection<PSObject> results = pipeline.Invoke();

           // close the runspace
           runspace.Close();

           // convert the script result into a single string
           StringBuilder stringBuilder = new StringBuilder();
           foreach (PSObject obj in results)
           {
               stringBuilder.AppendLine(obj.ToString());
           }

           // return the results of the script that has
           // now been converted to text
           return stringBuilder.ToString();
       }

     

    VB:

    ' Takes script text as input and runs it, then converts
        ' the results to a string to return to the user
        Private Function RunScript(ByVal scriptText As String) As String

            ' create Powershell runspace
            Dim MyRunSpace As Runspace = RunspaceFactory.CreateRunspace()

            ' open it
            MyRunSpace.Open()

            ' create a pipeline and feed it the script text
            Dim MyPipeline As Pipeline = MyRunSpace.CreatePipeline()

            MyPipeline.Commands.AddScript(scriptText)

            ' add an extra command to transform the script output objects into nicely formatted strings
            ' remove this line to get the actual objects that the script returns. For example, the script
            ' "Get-Process" returns a collection of System.Diagnostics.Process instances.
            MyPipeline.Commands.Add("Out-String")

            ' execute the script
            Dim results As Collection(Of PSObject) = MyPipeline.Invoke()

            ' close the runspace
            MyRunSpace.Close()

            ' convert the script result into a single string
            Dim MyStringBuilder As New StringBuilder()

            For Each obj As PSObject In results
                MyStringBuilder.AppendLine(obj.ToString())
            Next

            ' return the results of the script that has
            ' now been converted to text
            Return MyStringBuilder.ToString()

        End Function

     

     

    12.  Now we want to add in our LoadScript method to make getting the script into a variable easier.

     

    C#:

    // helper method that takes your script path, loads up the script
            // into a variable, and passes the variable to the RunScript method
            // that will then execute the contents
            private string LoadScript(string filename)
            {
                try
                {
                    // Create an instance of StreamReader to read from our file.
                    // The using statement also closes the StreamReader.
                    using (StreamReader sr = new StreamReader(filename))
                    {

                        // use a string builder to get all our lines from the file
                        StringBuilder fileContents = new StringBuilder();

                        // string to hold the current line
                        string curLine;

                        // loop through our file and read each line into our
                        // stringbuilder as we go along
                        while ((curLine = sr.ReadLine()) != null)
                        {
                            // read each line and MAKE SURE YOU ADD BACK THE
                            // LINEFEED THAT IT THE ReadLine() METHOD STRIPS OFF
                            fileContents.Append(curLine + "\n");
                        }

                        // call RunScript and pass in our file contents
                        // converted to a string
                        return fileContents.ToString();
                    }
                }
                catch (Exception e)
                {
                    // Let the user know what went wrong.
                    string errorText = "The file could not be read:";
                    errorText += e.Message + "\n";
                    return errorText;
                }

            }

     

    VB:

    ' helper method that takes your script path, loads up the script
        ' into a variable, and passes the variable to the RunScript method
        ' that will then execute the contents
        Private Function LoadScript(ByVal filename As String) As String

            Try

                ' Create an instance of StreamReader to read from our file.
                ' The using statement also closes the StreamReader.
                Dim sr As New StreamReader(filename)

                ' use a string builder to get all our lines from the file
                Dim fileContents As New StringBuilder()

                ' string to hold the current line
                Dim curLine As String = ""

                ' loop through our file and read each line into our
                ' stringbuilder as we go along
                Do
                    ' read each line and MAKE SURE YOU ADD BACK THE
                    ' LINEFEED THAT IT THE ReadLine() METHOD STRIPS OFF
                    curLine = sr.ReadLine()
                    fileContents.Append(curLine + vbCrLf)
                Loop Until curLine Is Nothing

                ' close our reader now that we are done
                sr.Close()

                ' call RunScript and pass in our file contents
                ' converted to a string
                Return fileContents.ToString()

            Catch e As Exception
                ' Let the user know what went wrong.
                Dim errorText As String = "The file could not be read:"
                errorText += e.Message + "\n"
                Return errorText
            End Try

        End Function

     

    13.  Finally, we just need to add some code for our button's click event.

     

    C#:

    private void button1_Click(object sender, EventArgs e)
            {
                // run our script and put the result into our textbox
                // NOTE: make sure to change the path to the correct location of your script
                textBox1.Text = RunScript(LoadScript(@"c:\users\zainnab\AddItUp.ps1"));
            }

     

    VB:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'run our script and put the result into our textbox
            'NOTE: make sure to change the path to the correct location of your script
            TextBox1.Text = RunScript(LoadScript("c:\users\zainnab\AddItUp.ps1"))
    End Sub

     

    14.  That's it!!  You should be able to run your code and you should get this:

    image

     

     

    Don't sweat it if you think this is a lot to type.  I have included the source code for you to use.  Enjoy!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio Update 1 Is Available!

    • 3 Comments

    The first update for VS2013 came out yesterday and is heavy on bug fixes but not much in the way of new functionality. You can download the latest update from here:

    http://www.visualstudio.com/downloads/download-visual-studio-vs#d-visual-studio-2013-update-1

     

     

    Here is a list with the new additions underlined:

    http://support.microsoft.com/kb/2911573

     

    ===

    Note Unless otherwise indicated, linked items will take you to Microsoft Connect webpages.


    Team Foundation Server

      Build
      • You cannot change the process parameters in the Queue Build dialog box in Visual Studio 2013.

     

    Debugger

    • Fixes screen reader compatibility for the "Debug Managed Memory" feature.
    • Updates the "Debug Managed Memory" feature to work on computers that have Windows Internet Explorer 9 installed.
    • MMA UI can be read by screen reader now.

     

    Directed Graph Markup Language

    • Non-ENU Visual Studio crashes when the Legend in a DGML document is updated by disabling or deleting any item in the legend list.

    Graphics Debugger

    • Graphics assets that are referenced by a graphics mesh are not deployed correctly.
    • When you capture a frame on a Windows 7 computer that does not have KB2670838 installed, you may receive the following error message:

      The Graphics Diagnostics engine couldn't create a debug device, most likely because the matching Windows SDK for this version of Windows is not installed. Please install the matching SDK and try again.

    Web Tools

    Visual C++

    • Assume that you edit a dialog that contains at least one picture control in Resource Editor. After you save the file, the project can no longer be compiled.
    • When you edit multiple resources in Resource Editor, Visual Studio crashes randomly.
    • Addresses some Visual C++ automatic formatting issues.
    • Visual C++ IDE does not work as expected if there is an unexpected registry subkey under the following registry key:
      HKCU\Software\Microsoft\VisualSTudio\12.0\FileExtensionMapping
    • When you try to link with PGO on amd64_x86 complier, Visual Studio crashes.

     

    IntelliTrace

    • IntelliTrace Viewer is updated to support Internet Explorer 9.

     

    Cloud Platform

    • "Object reference not set to an instance of an object" error message when an external user tries to save any intrinsic entity data from an Office 365-based cloud business application.

     

    Visual Studio Test

      Load Test
      • Visual Studio freezes when you try to run a load test in the cloud by using Visual Studio Online for the first time when there is no active connection to a Visual Studio Online account from your Team Explorer.
      • You cannot run load tests beyond 250 virtual users if you activated Visual Studio Ultimate by using an MSDN subscription.
      • When you activate Visual Studio by signing in to your Visual Studio online account by using your MSDN subscription id, you cannot run remote load tests, load tests together with a loadtest plugin or a virtual user load more than 250.
      • Load testing in Cloud with Visual Studio Online is broken on a computer that has Internet Explorer 9 installed. The Load Test Manager and Load Test Results windows do not render with Internet Explorer 9 correctly.
      • When there are multiple Visual Studio Online Accounts connected to in Visual Studio and none of them are active, one of the accounts is picked to communicate with the Load Testing in Cloud with Visual Studio Online, which results in a broken experience.
      • After you run a cloud-based load test by using Visual Studio Online, the "Download Result" operation fails for the first time. Additionally, you receive the following error message:

        There was an error while importing the result file. Details: The system cannot find the file specified. After correcting the problem open the results from Load Test Manager.

    XAML Tools

    • Improved the stability of the XAML designers in Visual Studio and Blend in a variety of scenarios for all XAML platforms (such as Windows Store, Windows Phone, Silverlight, WPF).
    • Addressed an issue concerning the packaging of Windows Store applications in which both XBF and XAML were packaged into a Windows Store AppX package when referencing Extension SDKs.

    XAML Designer

    • Allow controls compiled for Windows 8 to display in the Toolbox for Windows 8.1 projects.

    Release Management for Visual Studio 2013

    ===

  • The Ultimate Visual Studio Tips and Tricks Blog

    Turn Off the Uppercase Menu in Visual Studio 2012

    • 41 Comments

    I’ve been seeing a ton of posts lately on this feature so thought I would share here as well.  I also like to give credit where credit is due so I did a search and it looks like the earliest mention of this ability is by Richard Banks in his post 6\1\2012 here:  http://www.richard-banks.org/2012/06/how-to-prevent-visual-studio-2012-all.html  If anyone knows of an earlier one done by someone else let me know but this looks like the first mention of it.  If I were a betting man I would say he most likely used Process Explorer to make this discovery which is my favorite tool for finding things like this.

     

     

    Mixed Case is Your Friend

    Okay so you really, really don’t like the Uppercase menu in VS2012 because you feel like it is shouting at you:

    image

     

     

    You would rather go back to mixed case for your menu:

    image

     

     

     

    Not a problem! Let’s see how:

    WARNING:  Making changes to the registry can cause unexpected results so do any changes at your own risk!

     

    Manual Registry Change

    Open the registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General\
    (For Windows 8 Desktop Express go to HKCU\Software\Microsoft\WDExpress\11.0\General) //special thanks to msm8bball for the update
    (For Web Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWDExpress\11.0\General)



    1. Create a new DWORD value called SuppressUppercaseConversion set to 1
      image
    2. Restart Visual Studio and you should see the change

    NOTE: Watch your spelling if you are typing this manually.

     

     

    PowerShell Goodness

    If you like to “simplify” this a bit you can use PowerShell to run a nice script to make this happen.  However, if you haven’t used PowerShell before this may not be faster for you.

    1. Go to the Start button and type powershell and select the Windows PowerShell Entry:
      image
    2. In the PowerShell window copy the script below and paste it in then press Enter:
      Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\11.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1

      image
    3. Restart Visual Studio and enjoy!
  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013: TODO Comments and Custom Tokens in the Task List

    • 15 Comments

    NOTE: This is an older feature I’ve updated the information for VS2013

     

    Ever been writing some code and you want to leave a reminder to yourself to do something on a particular line or area?  Did you know about the "to do" comment feature or custom tokens?  They seriously rock if you have never used them and, because they go in source code, everyone can have access to the information when you check-in the code!

     

     

    TODO Comments

    So here's how TODO comments work: 

     

    VB

    In VB you just put any comment in that begins with the letters "todo" (case doesn't matter):

    5-16-2012 12-13-33 PM

     

     

    C# and C++

    In C# and C++, it's pretty much the same thing (again, case doesn't matter):

    5-16-2012 12-17-39 PM

     

     

    In C++ you have to explicitly turn this feature on.  Go to Tools | Options | Text Editor | C/C++ | View and change Enumerate Comment Tasks to True:

    5-16-2012 12-19-14 PM

     

     

    Regardless which language you use the result is an entry in your Task List:

    5-16-2012 12-22-52 PM

    Note: You can Double Click any entry to automatically have the editor go to the respective line in your source.

     

     

    If you don’t see the entries, make sure you have set the task list to see comments:

    5-16-2012 12-24-46 PM

     

     

     

    Custom Tokens

    We actually have several tokens you can use in addition to TODO. To see all the existing tokens go to Tools | Options | Environment | Task List:

    5-16-2012 12-28-08 PM

     

     

    HACK and UNDONE

    You are welcome to use HACK and UNDONE as well. The MSDN documentation is horrifically bad when it comes to describing these tokens and I don’t agree with the description of use necessarily. Here is what it says:

    “Items labeled TODO, HACK, and UNDONE in the Task List window indicate code problems that do not keep the project from compiling, but that do cause run-time errors. You should correct these errors before running the project.”

    http://msdn.microsoft.com/en-us/library/aa652344(v=VS.71).aspx

     

    Also, be aware that the number of entries that appear in the Task List changes depending on the type of project you are working on. With VB and C# projects, the Task List displays all of the comments in the project whether the file is open or not. With C++ projects, the Task List displays only the comments that are found in the files currently opened for edit.

     

     

    Creating Custom Tokens

    Feel free to create your own tokens for your use. Creating your own tokens is very simple, just pick a name for your token and type it in the Name textbox:

    5-16-2012 1-07-32 PM

    Note: UnresolvedMergeConflict looks like an error but isn’t it is an actual token that will make a high priority item in the Task List.

     

     

    Next choose a priority level:

    5-16-2012 1-09-02 PM

     

     

    Then click the Add button to make it an active token:

    5-16-2012 1-10-32 PM

     

     

    You will see it in your list:

    5-16-2012 1-11-42 PM

     

     

    Now you can use the token in your comments:

    5-16-2012 1-14-01 PM

     

     

    Sharing Custom Tokens

    Be aware that any tokens you create ARE NOT SHARED with other developers so you may want to come up with a standard set of tokens for everyone to use if you intend to leverage this feature company-wide then export them (http://blogs.msdn.com/b/zainnab/archive/2010/07/14/exporting-your-environment-settings-vstipenv0021.aspx) and have folks import them (http://blogs.msdn.com/b/zainnab/archive/2010/07/15/importing-or-changing-your-environment-settings-vstipenv0022.aspx).

     

     

     

    Finally

    Tokens are a pretty nice feature to keep track of places in your code you need to revisit. I don’t suggest them over, say, tasks in Team Foundation Server but they are a great short-term reminder for things that need to get attention. If you decide you would like to create Task List items programmatically you can do that as well. Here is a link to some guidance to get you started:

    http://msdn.microsoft.com/en-US/library/envdte.tasklist.defaultcommenttoken(v=vs.80).aspx

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Compatibility (aka Project Round-Tripping)

    • 4 Comments

    image

     

    Now that Visual Studio 2012 is pretty well baked I thought it would be good to start revisiting some of my favorite features again and introduce new ones.  Since project round-tripping is one of my most favorite features I thought we would start with it. 

     

    The Dark Ages

    In all prior incarnations of Visual Studio if you had an older version, VS2008 for example, and opened up the project in a newer version, VS2010 in this case, you had the option to convert the project.  If you did the conversion it was a one-way trip.  You couldn’t open the project again in VS2008 if you tried to go back.  This has been the source of a lot of pain and suffering for developers who have to work with multiple versions of Visual Studio for a long, long time.  We want the cool features of the latest IDE but still want others on our team to be able to open the solution in the older version of Visual Studio when they get the files from source control.

     

    The Information Age

    Visual Studio 2012 changes the game.  You can now create projects in Visual Studio 2010 with Service Pack 1 then open those projects in Visual Studio 2012 and THEN open the project up again in VS2010 SP1.  This works the other way, too!  You can create projects in VS2012 (targeting Framework version 4 or less) then open the project in VS2010 SP1 and THEN open it up in VS2012 again. In other words, we now have project round-tripping capability so you can work with the latest features but still keep the solution compatible with team members using an older version of Visual Studio.

     

    Putting it to the Test

    Here are the steps you can take to test this for yourself:

    1. Create a compatible project (see fine print below) in Visual Studio 2010 with Service Pack 1 and put in a little sample code.
    2. Save and close the solution.
    3. Open the solution (CTRL + SHIFT + O) in Visual Studio 2012 and add some more code.  Notice there is no longer a prompt to convert the project that appears.
    4. Save the close the solution.
    5. Open the project up again in VS2010 SP1 and enjoy project round-tripping.

     

    The Fine Print

    As you probably guessed by now this doesn’t work with every project type and there are some limitations based on the project type you use.  For the full list of project types and limitations you can go here:

    http://msdn.microsoft.com/en-us/library/hh266747(VS.110).aspx

     

    Here is an edited list of the ones you are most likely to use:

    Type of Project

    Compatibility

    C#/Visual Basic Silverlight 4 or 5 Application or Class Library

    If you allow Visual Studio to update the project automatically, you can open it in either Visual Studio 2012 RC or Visual Studio 2010 with SP1.

    C#/Visual Basic Webform or Winform

    You can open the project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

    Coded UI test

    If you allow Visual Studio to update the project automatically, you can open it in both Visual Studio 2012 RC and Visual Studio 2010 with SP1. For more information, see Upgrading Tests from Earlier Versions of Visual Studio.

    Model-View-Controller framework

    If the Model-View-Controller (MVC) project uses version 3 or 4, you can open this project in Visual Studio 2012 RC. By default, Visual Studio 2010 with SP1 supports only MVC 2 and 3, and Visual Studio 2012 RC supports only MVC 3 and 4.

    For information about how to automatically upgrade from MVC 2 to MCV 3, see ASP.NET MVC 3 Application Upgrader. For information about how to manually upgrade from MVC 2 to MVC3, see Upgrading an ASP.NET MVC 2 Project to ASP.NET MVC 3 Tools Update. If your project targets the .NET Framework 3.5 with SP1, you must retarget your project to use the .NET Framework 4.

    MSI setup (.vdproj)

    You can’t open this project in Visual Studio 2012 RC because it doesn't support that project type. We recommend that you use InstallShield Limited Edition for Visual Studio (ISLE), a free deployment solution that directly supports most Windows platforms and application runtimes. ISLE also supports importing data and settings from Visual Studio Installer projects. For more information, see Windows Installer Deployment.

    Office 2010 VSTO

    If the project targets the .NET Framework 4, you can open this project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

    SharePoint 2010

    You can open the project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

    SQL Server 2008 R2 Express

    If SQL Server 2008 R2 Express is installed on the computers that are running Visual Studio 2012 RC and Visual Studio 2010 with SP1, you can open the project in both of those versions of Visual Studio.

    SQL Server Report Project

    You can open the project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1. For local mode only (that is, when not connected to SQL Server), you won’t get the design-time experience for controls that are associated with the viewer in Visual Studio 2010, but the project will function correctly at runtime.

    Caution note Caution

    If you add a feature that’s specific to Visual Studio 2012 RC, the report schema will be upgraded automatically, and you will no longer be able to open the project in Visual Studio 2010 with SP1.

    Unit tests

    You can use Microsoft Test Manager 2010 with SP1 in Visual Studio and Visual Studio 2012 RC to open tests that were created in either of these versions. For more information, see Upgrading Tests from Earlier Versions of Visual Studio.

    Visual C++

    If Visual Studio 2012 RC and Visual Studio 2010 with SP1 are installed on the same computer, you can open the project in both of those versions of Visual Studio. For more information, see How to: Upgrade Visual C++ Projects to Visual Studio 2012.

    Visual Studio 2010 web

    If you allow Visual Studio to upgrade the project automatically, you can open it in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

    Visual Studio 2010 Database (.dbproj)

    If you convert the project to a SQL Server Data Tools Database project, you can open it in Visual Studio 2012 RC. However, Visual Studio 2012 RC doesn’t support the following artifacts:

    • unit tests

    • data-generation plans

    • data-comparison files

    • custom rule extensions for static code analysis

    • server.sqlsettings

    • .sqlcmd files

    • custom deployment extensions

    • partial projects (.files)

    If you install SQL Server Data Tools, you can open the project in Visual Studio 2010 with SP1 after the migration. For more information, see Microsoft SQL Server Data Tools.

    VS 2010 SQL Server Data Tools

    You can open this project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

    Visual Studio Lab Management

    You can use Microsoft Test Manager in Visual Studio 2010 with SP1 or Visual Studio 2012 RC to open environments that were created in either of these versions. However, your version of Microsoft Test Manager must match your version of Team Foundation Server before you can create environments. For more information, see Upgrading Lab Management Components from Visual Studio 2010.

    Visual Studio SDK/VSIX

    If you upgrade the project, you can open it in Visual Studio 2012 RC only. For more information, see How to: Upgrade Visual Studio SDK/VSIX Projects to Visual Studio 2012.

    Windows Communication Foundation, Windows Presentation Foundation

    You can open this project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

    Windows Mobile

    You can’t open this project in Visual Studio 2012 RC because it doesn't support the project type.

    Windows Phone

    You can’t open this project in Visual Studio 2012 RC because it doesn't support the project type.

    Other

    You can open most other types of projects in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

     

    For a more detailed explanation of why this is the case and how the decision making process was done by the VS team make sure to read Richa Prasad’s most excellent blog post here:

    http://blogs.msdn.com/b/visualstudio/archive/2012/03/28/round-tripping-with-visual-studio-11.aspx

     

    Richa does a great job of explaining the overall decisions around this feature as well as showing what happens (and what you can expect to see) in those scenarios where it isn’t as clean. 

     

    For example, here is what you would see when trying to import a setup project that is no longer supported:

    SNAGHTMLa85d81d

     

    And here is the resulting migration report generated by Visual Studio 2012:

    image

     

    And there you have it!  Give project round-tripping a shot yourself and see if you think it’s great, too!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Code Metrics – Cyclomatic Complexity

    • 10 Comments

    SKU: Premium, Ultimate

    Versions: 2008, 2010

    Code: vstipTool0131

     

    When working with code metrics, one of the least understood items seems to be cyclomatic complexity. Essentially, with cyclomatic complexity, higher numbers are “bad” and lower numbers are “good”. We use cyclomatic complexity to get a sense of how hard any given code may be to test, maintain, or troubleshoot as well as an indication of how likely the code will be to produce errors. At a high level, we determine the value of cyclomatic complexity by counting the number of decisions made in our source code. In this tip we will start out with a simple example of cyclomatic complexity to understand the concept quickly then give some additional information on actual usage and suggested limits. Finally, I’ve added a section of citations that can be used to dig deeper into this subject.

     

    Cyclomatic Complexity: A Simple Example

    Cyclomatic complexity is defined as measuring “the amount of decision logic in a source code function” [NIST235]. Simply put the more decisions that have to be made in code, the more complex it is.

    Let’s see it in action. Create a new console application and immediately calculate your code metrics by going to Analyze | Calculate Code Metrics for Solution:

    image

     

    Notice the cyclomatic complexity is at 2 (the lowest value possible). If I add non-decision code, notice the complexity doesn’t change:

    image

     

     

    If I add a decision, the cyclomatic complexity value goes up by 1:

    image

     

    When I change the if statement to a switch statement with 4 decisions to be made then it goes from the original 2 to 6:

    image

     

    Let’s take a look at a larger code base. Here are the metrics from the Tailspin Toys sample code (http://msdn.microsoft.com/en-us/library/aa645517(VS.71).aspx):

    image

     

    Notice that most of the items, as we drill down into the Products_Related class, have a value of 1 but a couple of them have a complexity of 5. By itself this may not be a big deal, but given that most other members have a 1 in the same class I would definitely look closer at those two items and see what is in them. You can do this by right-clicking the item and choosing Go To Source Code from the context menu. Let’s take a closer look at Product.set(Product):

    image

     

    Given all the if statements, we can see why the cyclomatic complexity is at a 5. At this point we may decide that this is an acceptable level of complexity or we might refactor to reduce the complexity.

     

     

    The Magic Number

    As with many metrics in our industry, there is no exact cyclomatic complexity limit that fits all organizations. However, [NIST235] does indicate that a limit of 10 is a good starting point:

    “The precise number to use as a limit, however, remains somewhat controversial. The original limit of 10 as proposed by McCabe has significant supporting evidence, but limits as high as 15 have been used successfully as well. Limits over 10 should be reserved for projects that have several operational advantages over typical projects, for example experienced staff, formal design, a modern programming language, structured programming, code walkthroughs, and a comprehensive test plan. In other words, an organization can pick a complexity limit greater than 10, but only if it is sure it knows what it is doing and is willing to devote the additional testing effort required by more complex modules.” [NIST235]

     

     

    Cyclomatic Complexity and Line Numbers

    As I mentioned in vstipTool130 (“Code Metrics – Lines of Code”), just looking at the number of lines of code by itself is, at best, a very broad predictor of code quality. There is some basic truth to the idea that the more lines of code in a function, the more likely it is to have errors. However, when we combine cyclomatic complexity with lines of code then we have a much clearer picture of the potential for errors.

    As described by the Software Assurance Technology Center (SATC) at NASA:

    “The SATC has found the most effective evaluation is a combination of size and [Cyclomatic] complexity. The modules with both a high complexity and a large size tend to have the lowest reliability. Modules with low size and high complexity are also a reliability risk because they tend to be very terse code, which is difficult to change or modify.” [SATC]

     

     

    Code Analysis

    When using code analysis, the Design Guideline rule sets contain maintainability areas:

    image

     

    Inside the maintainability area is a rule for complexity:

    image

     

    This rule issues a warning when the cyclomatic complexity reaches 25 so it is a good thing to have to keep you from having excessive complexity. You can learn more about the rule here: http://msdn.microsoft.com/en-us/library/ms182212.aspx

     

     

    Special Note on Visual Studio 2010

    There may be differences when calculating code metrics using Visual Studio 2010 that don’t apply to Visual Studio 2008. The online documentation (http://msdn.microsoft.com/en-us/library/ee703787.aspx) gives the following reasons:

    • The function contains one or more catch blocks. In previous versions of Visual Studio, catch blocks were not included in the calculation. In Visual Studio 2010, the complexity of each catch block is added to the complexity of the function.
    • The function contains a switch (Select Case in VB) statement. Compiler differences between Visual Studio 2010 and earlier versions can generate different MSIL code for some switch statements that contain fall-through cases.

     

     

    Putting It All Together

    The bottom line is that a high complexity number means greater probability of errors with increased time to maintain and troubleshoot. Take a closer look at any functions that have a high complexity and decide if they should be refactored to make them less complex.

     

     

    Citations

    [MCCABE5]

    McCabe, T. and A. Watson (1994), Software Complexity (CrossTalk: The Journal of Defense Software Engineering).

     

    [NIST235]

    Watson, A. H., & McCabe, T. J. (1996). Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric (NIST Special Publication 500-235). Retrieved May 14, 2011, from McCabe Software web site: http://www.mccabe.com/pdf/mccabe-nist235r.pdf

     

    [SATC]

    Rosenberg, L., Hammer, T., Shaw, J. (1998). Software Metrics and Reliability (Proceedings of IEEE International Symposium on Software Reliability Engineering). Retrieved May 14, 2011, from Penn State University web site: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.4041&rep=rep1&type=pdf

Page 1 of 135 (1,345 items) 12345»