Update: see the third post here.
OK, continuing with my previous post, here are some more Visual Studio tips, this time, with a lot more pictures!
- Start several projects simultaneously: when it comes to starting a project in a solution, there are three options:
- Start a single, fixed, project;
- Start the project where the focus is currently on;
- Start multiple projects simultaneously.
Right click on the solution – Properties – Common Projects – Startup Project and select Multiple startup projects:
- 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:
Then, check the ones that you are interested in:
- 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:
Now you can add any condition you want, either based on local or global variables and methods – watch out for any possible side effects!
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:
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:
- 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:
Now, add an output string, which can take variables, parameters or properties, plus some special tokens:
- 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:
- 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:
- 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:
Then select the encoding and line ending you want:
- 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:
- 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):
- 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 Moseley: http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx.
I will be back!