Visual Studio Tips 5
This is the fifth post of my Visual Studio tips series. See the first one here, the second here, the third here and the fourth here.
- Abort build: before exiting Visual Studio or retrieving changes from source control, any ongoing build must finish. If you don’t want to wait, you can abort it by pressing <Ctrl>-<Break>
- Start Visual Studio in safe mode helps in debugging problems introduced by some extensions. In the command line just enter: devenv /SafeMode
- Object IDs: you can track variables and fields in the debugger even when they go out of scope by creating an object id (1, 2, etc) for it. First add the variable or field to the watch window and then select Make Object ID:
Then you can inspect it at any time you want just by adding it to the watch as $1, $2, etc: - You can now add breakpoints to Auto-Properties, in the getter or setter! Cool!
- NuGet Package Suggestion for Unrecognized Types:Visual Studio can suggest automatically installing a specific NuGet package to resolve an unknown type found in the code, or one that you may have typed yourself. This needs to be enabled.
- Query Syntax in Go To All (Ctrl+T): when querying Go To All, you have some prefixes to help narrow your search results:
- f {file}: for files
- t {type}: for types
- m {member}: for any type member
- # {symbol}: for any symbol
- No side effects: sometimes, when debugging, we may need to evaluate an expression (property, method) that causes side effects, like, changes the internal state of some class. When we don’t want this to happen, we can add nse to the end of the expression, and it will prevent any unwanted side effects:
- Copy files upon project build: you can use Visual Studio (or, better, MSBuild) to copy files for you during project build. Just add something like this to your .csproj:
- Paste ring: Visual Studio keeps several items in its internal Clipboard. You can iterate through them all by clicking Ctrl+Shift+V:
- Using Visual Studio to compare files. There are two ways:
- Using the command line: devenv /diff “Program.cs” “Program – Copy.cs”
- Using the Command Window: Tools.DiffFiles “Program.cs” “Program – Copy.cs” (shown below)
And this is it for now! Stay tuned for more!