Visual Studio Tips 2

Update: third post is here.

OK, continuing with my previous post, here are some more Visual Studio tips, this time, with a lot more pictures! Winking smile

  1. Start several projects simultaneously: when it comes to starting a project in a solution, there are three options:
    1. Start a single, fixed, project;
    2. Start the project where the focus is currently on;
    3. Start multiple projects simultaneously.

    Right click on the solution - Properties - Common Projects - Startup Project and select Multiple startup projects:

    image

  2. Break on exceptions: Visual Studio can break automatically on first-chance exceptions (ones that may be caught afterwards). This is useful, because if you have catch blocks, you might not even notice them. First-chance exception breaking can be defined on a class per class basis. First, click on Debug - Exceptions:

    image

    Then, check the ones that you are interested in:

    image

  3. Conditional breakpoints: you can enable breakpoints based on some condition on the code. First, create a breakpoint, right click in it, then click on Condition:

    image

    Now you can add any condition you want, either based on local or global variables and methods - watch out for any possible side effects!

    image

    Another option is to only break when the hit count - the number of times the program has processed the instruction - has reached some value. Click on Hit Count and select the right condition, break always is the default:

    image

    Yet another option is to add a filter. This is a limited condition, which can only take a couple of variables. Activate it by clicking on Filter:

    image

  4. Tracepoints: in the Ultimate edition of Visual Studio (sorry, folks that to not have it!) you can send output to the trace window without actually writing any code. How many times did you add a Trace.WriteLine call, or something similar, for this purpose? Create a breakpoint, then click When Hit:

    image

    Now, add an output string, which can take variables, parameters or properties, plus some special tokens:

    image

    image

  5. Showing or hiding items from Output window: while debugging your application, the Output windows tends to be cluttered with all sorts of messages. Well, you can hide some of them. Just right click on the Output window and check out those that you want to hide:

    image

  6. Add links: in a project, you can add physical files, which are copied to the project's folder, or links, which are kept in their original locations. Select Add - Existing Item, navigate to the folder containing the file you want to add, select it, but instead of clicking Add, select Add As Link from the drop down:

    image

  7. Save text files with different encoding: due to several reasons, you might need to save a text file with a particular encoding. When about to save the file, click the drop down in the Save button and select Save with Encoding:

    image

    Then select the encoding and line ending you want:

    image

  8. Preview Web.config transformations: ASP.NET Web.config Transformations were introduced in Visual Studio 2010 and allow us to perform transformations on the Web.config file based on the current configuration - Debug, Release, etc, upon deployment. The problem is, most of you don't know it's possible to view the result file without actually deploying the application, but it is! Right click on a transformation file, like Web.Release.config, and select Preview Transform:

    image

  9. Generate ASP.NET designer files: when your ASP.NET web forms designer files - like Default.Designer.aspx.cs - become corrupted, for whatever reason, it's better to remove them and have them generated by Visual Studio. Right click on the markup file - .aspx, .master or .ascx - and click on Project - Convert to Web Application (weird choice of name, I know):

    image

  10. Debug MSBuild scripts: I left the best for last! It's possible to debug .csproj build tasks, which are basically MSBuild tasks. I won't cover it all here, but instead make sure you read this post by Dan Moseleyhttp://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx.

I will be back! Winking smile

                             

1 Comment

Add a Comment

As it will appear on the website

Not displayed

Your website