Blog - Title

Visual Studio 2013 Current Status

  • The Ultimate Visual Studio Tips and Tricks Blog

    Print with Line Numbers


    Keyboard:  CTRL + P
    Menu:  File -> Print
    Command:  File.Print
    Versions:  2008,2010
    Published:  3/9/2010
    Code:  vstipEnv0006


    Want to print your line numbers with your code?  Don't worry!  You can do it by just checking the "Include line numbers" option in the Print Dialog:


  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2013: Turn Off the Uppercase Menu


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


    This is one change to Visual Studio that I’m not a fan of and I still continue to see a ton of posts on this change so thought I would share here as well. 


    I always try to give credit where credit is due and I believe the earliest mention of this fix is by Richard Banks in his post 6\1\2012 here: 




    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:

    5-16-2012 7-50-41 PM



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

    5-16-2012 7-43-08 PM


    Not a problem! Below are ways you can fix this feature in VS2013.




    Manual Registry Change

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

    1. Open the registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\General\
      (For Windows 8 Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWinExpress\12.0\General)
      (For Web Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWDExpress\12.0\General)

    2. Create a new DWORD value called SuppressUppercaseConversion set to 1

    3. Restart Visual Studio and you should see the change

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




    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 or (Start Screen in Windows 8) and type powershell then select the Windows PowerShell Entry:


    2. In the PowerShell window copy the script below and paste it in then press Enter:

      Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\12.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1


    3. Restart Visual Studio and you are good to go.
  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 11 Developer Preview - Project Backward Compatibility (Round-Tripping)



    [ NOTE:  This post has been depricated.  The new, updated post can be found here: ]




    UPDATE 3/8/2012:  As of the Beta this does not work with all project types.  Most notably web projects are not supported currently for this feature.  For more information on what is supported and what isn't look here:


    Probably one of the most welcome new features in VS11DP is the new project backward compatibility feature also known as project round tripping.  Let’s dig into the details.


    The Old Days

    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.  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 New, Happy Days

    You can now create projects in Visual Studio 2010 with Service Pack 1 then open those projects in Visual Studio 11 Developer Preview and THEN open the project up again in VS2010SP1.  In other words, we now have full project round-tripping capability so you can work with the latest features but still keep the solution compatible with and 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 project with 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 11 Developer Preview 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 VS2010SP1 and bask in the glory of project round-tripping.


    Limitations / Observations

    • I know this works with Visual Studio 2010 Service Pack 1 but haven’t tested VS2010 with out the service pack.  I believe it will not work unless you have the service pack but am checking with the team.
    • You can’t use this feature with versions older than VS2010.
    • When you use any feature specific to the new version of Visual Studio, like changing the Framework to the latest version, then the project cannot be opened in the prior version.  I just changed the framework version from 4.0 to 4.5 for a project and saved it without many any other change and was not able to open the solution in VS2010.
  • The Ultimate Visual Studio Tips and Tricks Blog

    TODO Comments in the Task List


    Versions:  2008,2010
    Published:  6/7/2010
    Code:  vstipTool0029


    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?  It seriously rocks if you have never used it AND, because it goes in the source code, everyone can have access to the information when you do you check-in!


    So here's how it works:  In VB you just put any comment in that begins with the letters "todo" (case doesn't matter):



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



    C++ requires that the “TODO” be in upper-case or it will not show up in the Task List:




    In C++ for VS2010 you have to explicitly turn this feature on.  Go to Tools | Options | Text Editor | C/C++ | Formatting | Miscellaneous and change Enumerate Comment Tasks to true:




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



    NOTE:  In order to see these items, you have to click the drop-down list in the Task List and choose Comments as shown here.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Turn on Line Numbers


    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:


  • The Ultimate Visual Studio Tips and Tricks Blog

    Setting Bookmarks


    Keyboard:  CTRL + K, CTRL + K (toggle bookmark)
    Menu:  Edit -> Bookmarks -> Toggle Bookmark
    Command:  Edit.ToggleBookmark
    Versions:  2008,2010
    Published:  7/5/2010
    Code:  vstipTool0047


    Bookmarks are a pretty cool feature that a lot of people don't seem to know about.  Essentially, Bookmarks are a way to mark locations in your code.  Unlike tokens ("TODO's"), Bookmarks are not stored with the source code.  There are numerous ways to set a Bookmark.  The simplest way is to use CTRL + K, CTRL + K to create a single Bookmark:



    When you set a Bookmark it will create a glyph in the Margin and create an entry in the Bookmarks Window:



    The good news is you don't have to keep the default name that is given for the Bookmark.  Just RIGHT CLICK the entry in the window and choose "Rename":



    Then put in whatever you want for the name and you are good to go:



    You can continue to use this method or the menu to create Bookmarks.  Another cool way to create Bookmarks is to use the "Bookmark All" (bottom right) button in the Quick Find dialog (CTRL + F):


  • The Ultimate Visual Studio Tips and Tricks Blog

    Ever Give Your Dog Mouth-To-Mouth?



    Well!  I had an interesting night.  As many of probably know by now we have four dogs at my house:  Max (Basenji), Fibi (Jack Russell Terrier), Lily aka Piggy (we think she is a Pit Bull mix), and Zorro (Blue Tick mix).  With four dogs you are always breaking up little fights between them at one time or another.  Not sure if it is just our dogs or this is a normal thing. 


    Last night my dogs were in the backyard and I heard a little skirmish start.  I did my usual yell to tell them to cut it out but this time Zorro kept making a funny noise like he was hurt.  It didn't sound good at all.  I went out side and found Max and Zorro attacking Lilly.  Normally Lilly can handle herself no problem but she didn't seem to be fighting and it looked like Zorro had her around the neck. 


    As I approached and got Zorro to hold still I discovered that he had managed to get his lower jaw stuck in Lilly's collar.  As I looked closer I found I was having a hard time getting Zorro lose so I brought them closer into the light near our porch.  That is when I realized there was a bad problem.  Zorro was really stuck and there was blood all over Lilly. 


    I called for my wife to come down and give me some help and she began looking for a flashlight to get a better idea of what we were dealing with.  Right after she left, I noticed that Lilly had a funny look and realized she was choking--things were much worse than I thought.  OMG.  I almost freaked but held it together and called for my wife to bring me a knife (screw the collar, ill buy a new one).  It was close but I managed to cut the collar off w/o cutting Zorro or Lilly.  As soon as I cut them lose, I grabbed Lilly who had turned purple and had stopped breathing.


    I didn't know you could give a dog mouth-to-mouth but my wife (freaking out) managed to say "give her mouth-to-mouth".  Now, I have to admit, giving my dog mouth-to-mouth was not appealing to me but when you are faced with a purple dog you tend to not give a crap.  I directed her to start the car so we could take Lilly to the emergency room and gave the the dog mouth-to-mouth. 


    It worked!  I never, EVER would have thought you could resuscitate a dog that way but she started breathing slowly and we rushed her  to the emergency room.  By the time we got to the emergency room, she had completely restored breathing and was just a regular dog.  So there we were in our pajamas with a perfectly healthy dog just wagging it's tail and having a good time.  About 30 minutes and 95 dollars later we were on our way home and now we are looking for a new (hopefully safer) collar for Lilly. :P

  • The Ultimate Visual Studio Tips and Tricks Blog

    LINQ and Stored Procedures


    Okay so last quarter I was asked if you can call stored procedures using Language Integrated Query (LINQ).  The answer, of course, is YES!  It would be kind of silly if we didn't include this type of functionality. :P


    NOTE:  You need the following items to do this example

    SQL Server (pretty much any version will do but this example uses 2005)

    Visual Studio 2008 (Beta 2 was used for this example)

    A little time to sling some code



    So how exactly DO you call a stored proc using LINQ?  Easy just follow these simple steps:

    1. Create a new Windows Forms Application in Visual Studio 2008, let's call it "LINQ_SP_Coolness"

    2. Next, make sure you have a connection to some data source in your Server Explorer.  You may need to add a new connection.

    3. For the purposes of this discussion I am using the Northwind Database on SQL Server.

    4. Take a look at the existing stored procedures because what you need may already be there.

    5. Aaaaaand since I'm bored watching re-runs tonight, why don't we make our own stored procedure?

    6. Just write a simple SELECT to yank out some data AND remember to save :)

    7. Just to make sure, refresh the stored procedure folder on your data source in Server Explorer to see your shiny, new stored proc listed...

    8. You might even want to test it :P

    9. To get this to a point we can manipulate it using LINQ we need to have our classes and mappings in place.  Fortunately, this is a VERY easy thing to do.  Just right-click your project, choose Project...Add New Item from the Menu Bar.  Let's add a "LINQ to SQL Classes" item with the default name of "DataClasses1.dbml".

    10. Click and drag the stored procedure from Server Explorer on to the LINQ design surface.

    11. You should see the procedure showing up on the upper right of the design surface.

    12. Now let's slap some controls on our Windows Form.  How about a list box and a button?  Live on the edge!

    13. Now we need to work with database by establishing a context to it.  Next, we need to create a query expression that treats the result of the stored procedure as a table and query against it selecting only the LastName column.  Just for fun why don't we sort all the last names as well?  Finally, we will take the list of names returned and loop through them adding each one to our listBox as we go along.

      Double-click on the button to code for the Click event and write the following lines of code:
      (NOTE: make sure to substitute your server name in place of "zero_cool" and if you are using SQL Express you need to modify the server piece to read like this "SQLEXPRESS\myserver")

    14. If all goes well, you should get the following result:

    15. And that's how you use a stored procedure with LINQ.  This was a very simple example but if you really want to see a great series on LINQ go to my buddy Benko's site.   He has a webcast series on LINQ that kicks major butt! :)

      [Updated:  added tags]
  • The Ultimate Visual Studio Tips and Tricks Blog

    Calling a PowerShell Script From Your .NET Code



    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:


    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: 


    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:






    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 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.






    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.








    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...






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










    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




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





    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:





    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. 



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



    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. 



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

           // open it

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

           // 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.

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

           // close the runspace

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

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



    ' 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

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


            ' 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.

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

            ' close the runspace

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

            For Each obj As PSObject In results

            ' 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.



    // 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)
                    // 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;




    ' 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


                ' 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
                    ' 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

                ' 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.



    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"));



    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:




    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

    The RTM of Visual Studio 2008 Is Coming


    [EDIT:  As Guy pointed out on his blog VS2008 is RTM for MSDN already]


    By now it is no secret that Visual Studio 2008 will RTM before the end of November.  Soma mentioned this at TechEd Europe and I couldn't be more excited!  Make sure you are getting ready with for the new version by checking out our webcasts and other training materials that are available.  Here is a list of places to help you get prepared:


    Main Visual Studio 2008 Product Page


    Main World Wide Events Website

    NOTE:  Don't let the name throw you off, this is your best "one stop shop" for getting MS content.  Make sure to take advantage of the Virtual Labs!  Below is an extremely short list  at what I found when I searched on the keyword "linq":




    Channel 9 (of course)



    And of course the various blogs (on the left hand side) and other resources that crop up.   I will be doing a 26 part webcast on new features of VS2008 beginning in December as well.



    In the meantime, let's have a contest.   Post here with your list of resources for getting up to speed with VS2008.  I will randomly choose one person to be the recipient of ONE of these prizes (winner's choice):


    Windows Vista Ultimate

    Office 2007 Ultimate

    Halo 3/Flight Simulator X  Combo gift

    [Edit:  contest extended until 12/1 by popular demand!]

    Just in time for the holidays!  Contest ends on 11/26/2007 @ 5pm Central.  Good Times :)


    (MS employees not eligible but shoot me an email if you would like to see an FTE version of this contest)


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