Visual Studio Tips and Tricks: Increasing your Productivity for .NET

Mika Dumont

The .NET team is constantly thinking of new ways to make developers more productive. We’ve been working hard over the past year to take the feedback you’ve sent us and turn it into tools that you want! In this post I’ll cover some of the latest productivity features available in Visual Studio 2019 Preview.

Code Fixes and Refactorings

Code fixes and refactorings are the code suggestions the compiler provides through the lightbulb and screwdriver icons. To trigger the Quick Actions and Refactorings menu type (Ctrl .) or (Alt + Enter). The list below contains the code fixes and refactorings that are new in Visual Studio 2019 Preview. We’d like to give a big thanks to the community for implementing and reviewing many of these! 

 

Wrap call chain
You can now wrap chains of method calls with a refactoring.

Wrap Call Chains

 

Rename a file when renaming a class
You can now rename a file when renaming an interface, enum or class.
Rename File when Renaming a Class

 

Sort usings is back!
We brought back the sort usings command separate from the Remove and Sort Usings command. You can now find the Sort Usings command in Edit > IntelliSense.
Sort Usings

 

Convert a switch statement to a switch expression
You can now convert a switch statement to a switch expression. In your project file make sure the language version is set to preview since switch expressions are a new C# 8.0 feature.
Convert a Switch Statement to a Switch Expression

 

Generate a parameter
You can now generate a parameter as a code fix.
Generate Parameter

 

Toggle comment/uncomment
Toggle single line comment/uncomment is now available through the keyboard shortcut (Ctrl + K, /). This command will add or remove a single line comment depending on whether your selection is already commented.
Toggle block comment/uncomment is now available through the keyboard shortcut (Ctrl + Shift + /). This command will add or remove block comments depending on what you have selected.
Toggle Block Comment/Uncomment

 

Move type to namespace
You can now use a refactoring dialog to move type to namespace or folder.
Move Type to Namespace

 

Move Type to Namespace Dialog

 

Split or merge if statements
We now have a code fix for split/merge if statements.
Split or Merge If Statements

 

Wrap binary expressions
We now have a code fix for wrap binary expressions.
Wrap Binary Expression

 

Get Involved

This was just a sneak peak of what’s new in Visual Studio 2019 Preview, for a complete list see the release notes and feel free to provide feedback on Developer Community, and using the Report a Problem tool in Visual Studio.

15 comments

Discussion is closed. Login to edit/delete existing comments.

  • Michał Rzepa 0

    Where are vertical tabs? I still cannot use vs 2019 because of that missing feature… 

    • Immo LandwerthMicrosoft employee 0

      You mean the document tabs (as opposed to the character \v), right? 

      • First name Last name 0

        No, he means vertical document well, which was not ported to vs2019 for no reason

        • Daniel Neely 0

          Apparently it’s a casualty of them doing a major refactor to limit plugin’s ability to slow VS down.  Vertical tab well uses old depricated APIs.  I’ve just stuck with VS2017 instead of trying, but have read that you can download and unzip the installer, and patch a config file to set an override flag to make it install in 2019 despite the deprecated API usage.

          • John Cardinal 0

            I am sticking with VS2017 for the same reason. I am sure some (many?) users complained about slow startup speeds, but I never noticed it and easy navigation between 20 or so document tabs is way more important to me than a slight slowdown when opening a solution. I open solutions a couple times a day, but I navigate between tabs frequently.

  • Max Mustermueller 0

    Wrap call chain is a true gift. I’ve been using it a lot since it has been added. Converting switch expression however I was excited about but I cannot find this menu item although my project uses C#8. Does it only work on single line switch statements like shown in the example?

  • Andrew Cutforth 0

    Also you can add instant backup unlimited undo and diff while you are working with AJC Active Backup which has a Visual Studio plugin.  This protects you from mistakes, file corruption and reminds you what you have done with diffs while you are working.  It automatically backs up your files every time you save into compact archives.  You may check your code into version control at the end of the job/day but this protects you up to the second.
    You can read more about the Visual Studio add in here

  • Greg Sas Granger 0

    I really like the split/join if and wrap call chain.  Is there control of the nature of the formatting for these?  I’d love to be able to line up the ‘.’ under the first ‘.’ of the root line.  In complex if’s I like to line up the &&/|| with the ‘if’ (assuming same level of logic).  VS is a wonderful tool and I’m so happy MS continues to improve and refine it.
    Oh, and does anyone know the keyboard short cut to put a caret at the end of each selected line (multi-caret, ragged line endings) so I can do things like add a ‘);’ to all the selected lines at once (like Shift-Alt-I in VS Code) ?

    • KendraHavensMicrosoft employee 0

      I’m glad to hear that! We have an open issue on making the preferred wrapping options configurable via editorconfig: https://github.com/dotnet/roslyn/issues/33872. We appreicate you upvoting and sharing your thoughts to let us know what features are important to the most users!

      Insert caret at end of each line in a given selection. (Shift + alt + i) in VSCode: this is not a part of the built-in tools of Visual Studio. Would you mind opening a suggestion for this? https://developercommunity.visualstudio.com/ Thank you!

  • Radium Zheng 0

    Is there a command line tool for code fixes and things like sorting usings? 

  • Gauthier M. 0

    Thanks to VS dev team to include all of these useful features 🥰
    Soon we don’t required Resharper to code in C# easily (refactoring, autocompletion, etc…)😋

  • Heinrich Moser 0

    1. I think it’s great that you add new refactorings! 🙂
    2. I think it’s a pity that you decided not to fix existing refactorings. 🙁

  • Ruslan Shupoval 0

    Thank you for this update. I have one question regarding the “Sort Usings” feature. At this moment “sort usings” just sort them alphabetically. Is there a way to customize the default behaviour of “sort using”? In my projects I’d like to sort usings in the following order: 1. System.* 2. Microsoft.* 3. 3rd party. 4. This solution/project. Usings within each group are being sorted alphabetically.

Feedback usabilla icon