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.

  1. 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>
  2. Start Visual Studio in safe mode helps in debugging problems introduced by some extensions. In the command line just enter: devenv /SafeMode
  3. 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:
  4. You can now add breakpoints to Auto-Properties, in the getter or setter! Cool!image
  5. 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.image
  6. 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
  7. 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:image
  8. 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:image
  9. Paste ring: Visual Studio keeps several items in its internal Clipboard. You can iterate through them all by clicking Ctrl+Shift+V:
  10. Using Visual Studio to compare files. There are two ways:
    1. Using the command line: devenv /diff “Program.cs” “Program – Copy.cs”
    2. Using the Command Window: Tools.DiffFiles “Program.cs” “Program – Copy.cs” (shown below)


And this is it for now! Stay tuned for more!


No Comments

Add a Comment

As it will appear on the website

Not displayed

Your website