iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🙌

Essential Visual Studio 2022 Features for Robust and Efficient Code

に公開

Reprinted from my old blog


Abstract

This article organizes some useful and complementary features in Visual Studio 2022 to embody clean code.

Code analysis

  • Estimates the cleanliness of your code machinery
  • It's better to reconsider the code architecture if the Maintainability Index falls below 40.
  • Useful for:
    • Sniffing out the scent of technical debt
    • Use as a reference to determine standards to address
  • Menu:
    • Analyze -> Calculate Code Metrics -> For Solution
  • Result:

Code cleanup

  • Clean up the code throughout the entire solution
  • Apply it before committing
  • Useful for:
    • Maintaining an integrated formatting standard across a team
  • Menu:
    • Analyze -> Code cleanup -> Run Code Cleanup (Profile 1) on Solution

Performance profiler

  • Can monitor the performance of various resources
    • Database
    • File I/O
    • CPU / Memory Usage
  • Useful for:
    • Finding bottlenecks
    • Detecting anomalous behaviors
  • Menu:
    • Debug -> Performance profiler -> Check the resources to monitor -> Start button

Configuration

Monitoring

Monitor

Metrics

Shortcuts

Effect Shortcut
Jump Ctrl + G
Go To Definition F12
Go To Implementation Ctrl + F12
Navigate Backward Ctrl + -
Find All References Shift + F12
Quick search Ctrl + F
Search in Folders Ctrl + Shift + F
Code Search Ctrl + T

Tips: Code Search is good, all the time.

What's the difference between Search in Folders and Code Search?

  • The answer is:
    • Search in Folders: String-based search
    • Code Search: Signature-based search

So it skips searching for redundant lines like comments and navigates you to your target line more directly when you use code search.
I strongly recommend using code search if you don't require complex regex search or searching comments.

Edit

Effect Shortcut
Format Document Ctrl + K, Ctrl + D
Select word Ctrl + W
To Uppercase Ctrl + Shift + U
To Lowercase Ctrl + U
Move row Alt + ↑ or Alt + ↓
Duplicate row Ctrl + D
Complete word Ctrl + Space
Insert Block Ctrl + K, Ctrl + S

Tips: Insert Block is God

Haven't you used it yet? Why not?
Insert block provides a variety of general snippets such as for or if.
Don't write them yourself; rely on your IDE instead. It will boost your productivity more than tenfold!


Refactor

Effect Shortcut
Rename Ctrl + R, Ctrl + R
Extract Ctrl + R, Ctrl + M
Quick Action Ctrl + .

Tips: Move a literal into a constant

  1. Select the target literal
  2. Press Ctrl + . to call Quick Actions
  3. Choose Introduce constant
  4. Rename the constant

Build / Debug

Effect Shortcut
Build Ctrl + Shift + B
Start Debug F5
Step over F10
Step in F11
Toggle breakpoint F9
Toggle enable breakpoint Ctrl + F9

Presentation

Effect Shortcut
Zoom In Ctrl + Shift + >
Zoom Out Ctrl + Shift + <

Conclusion

Visual Studio is a rich and reliable IDE for .NET developers. I love it and am honing my skills to be a good pilot for it.
However, I do have some frustrations with it and hope that Microsoft will modify or add new features like the following:

  • Give me a default test coverage reporter.
  • Why not add a CamelCase/SnakeCase converter?
  • Let me jump to the implementation when I Ctrl + Alt + Left click a signature, just like in ReSharper!
  • Keep the Quick Action menu displayed while I'm taking screenshots.

Discussion