Learn What’s New in .NET Productivity

Mika

The .NET Productivity team (aka. Roslyn) continues to enhance your developer productivity with the latest tooling updates in Visual Studio 2019. In the last release, we listened to your feedback and have been hard at work improving the .NET developer experience. To try out the latest .NET productivity enhancements download the latest Visual Studio release.

Tooling improvements

The feature that I’m most excited about is Inheritance margin. Inheritance margin provides a visual representation for navigating and inspecting the inheritance chain. Inheritance margin is off by default, so you’ll need to enable it in Tools > Options > Text Editor > C# or Basic > Advanced and select Show inheritance margin. Enabling inheritance margin will add new icons to the margins representing your code’s implementations and overrides. Clicking on the inheritance margin icon will display inheritance options that you can select to navigate to.

Inheritance Margin

Another exciting feature is the new Remove Unused References command. This command allows you to clean up project references and NuGet packages that have no usage. Removing project references that have no usage can help save space, reduce startup time of your application, and make NuGet restore faster. The Remove Unused References command will appear in the right-click menu of a project name or dependencies node in Solution Explorer.

Remove Unused References command

When you select Remove Unused References, a dialog box will open where you can view all references that are going to be removed, but you also have the option to preserve any you wish to keep.

Remove Unused References dialog

EditorConfig files are a great way to define consistent code style and code quality preferences in your codebase. We received feedback that the configuration process wasn’t easy, so in 16.10 Preview 2 we added an EditorConfig designer allowing you to easily view and configure your code analysis preferences. To use the new designer, open any C# or Visual Basic EditorConfig file from your solution. The EditorConfig designer will display code analysis options for formatting, code style, third-party analyzers (i.e. if you have StyleCop or xUnit installed), and .NET code quality analyzers which we now include in the .NET 5.0 SDK. There is also an option to switch back to the EditorConfig text view by pressing F7.

EditorConfig designer

There’s a new command in town called Smart Break Line that automatically inserts a set of braces and places the caret within those braces when using Shift+Enter as a commit character. Smart Break Line works for all type declarations that require braces as well as properties, events, fields, and object creation expressions.

Smart Break Line

Using directives will now automatically get added when copying and pasting types to a new file. You’ll first need to turn this option on in Tools > Options > Text Editor > C# or Basic > Advanced and select Add missing using directives on paste.

Add missing usings on paste

Go To will no longer display duplicate results across .NET Core 2.0 and 3.1 apps as well as results for partial types that exist only to wrap another nested type. This will help declutter the results so you can easily find and navigate to code. The results also now include the filename for partial symbols.

Go To dialog

Edit and Continue (EnC) allows you to make changes to your source code during a debugging session while you’re in break mode, instead of having to stop, recompile your entire program, and restart the debugging session. Edit and Continue has some limitations, so not every edit is supported but in 16.10, we added support for editing partial classes, records, and add missing using directives. Edit and Continue also powers Hot Reload, which you can learn more about in the Introducing .NET Hot Reload blog!

IntelliSense completion

IntelliSense is a context-aware code completion feature that speeds up the process of coding applications by reducing typos and other common mistakes.

In 16.10 we added a completion option that automatically inserts arguments when writing a method call. This feature is off by default, so you’ll need to enable it in Tools > Options > Text Editor > C# > IntelliSense and select Tab twice to insert arguments (experimental). To use this feature, start writing a method call and press tab twice.

Method call argument completion

Notice that the method call includes arguments based on the method’s default values. Use parameter info to cycle through the list of arguments that you would like inserted by pressing the up and down arrow keys. Type semicolon, which will commit the arguments and add a semicolon to the end of the method call.

In 16.9 we added IntelliSense completion for Enum values when a type is known even if the Enum name is not entered. We decided to take this feature a step further by adding IntelliSense completion for casts, indexers, and operators.

IntelliSense completion for indexers

We also recently added IntelliSense completion for preprocessor symbols. Start typing the #if directive and notice the new completion options for symbols that are currently defined in scope.

Preprocessor symbols completion

Code fixes and refactorings

Code fixes and refactorings are the code suggestions the compiler provides through the light bulb and screwdriver icons. To trigger the Quick Actions and Refactorings menu, press (Ctrl+.) or (Alt+Enter). In case you missed it we added some exciting new code fixes and refactorings!

The Simplify LINQ expressions refactoring will remove the unnecessary call to the Enumerable for the .Where() method to help improve performance and readability. Place your cursor on the LINQ expression. Press (Ctrl+.) to trigger the Quick Actions and Refactorings menu. Select Simplify LINQ expression.

Simplify LINQ expression

Remove extra white space in a document with the new Remove extra blank lines code fix. Place your cursor on an extra blank line. Press (Ctrl+.) to trigger the Quick Actions and Refactorings menu. Select Remove extra blank lines.

Remove extra blank lines

In C# 9.0, discards are unnecessary in certain pattern matching cases. We now fade unnecessary discards and offer a code fix to remove them. Place your cursor on the faded discard. Press (Ctrl+.) to trigger the Quick Actions and Refactorings menu. Select Remove unnecessary discard.

Remove unnecessary discard

Razor tooling

In 16.7 Preview 4, we added the new Razor editor for local development with MVC, Razor Pages, and Blazor. The new Razor editor has a ton of new tooling support surpassing the functionality of the existing editor. For instance, we added a ton of C# code fixes and refactorings such as rename and add missing using directives.

Add missing using directive in a Razor file

Other improvements include support for Find All References in closed Razor files, Go to Definition on Blazor component tag names, Razor formatting, better diagnostics, Razor intrinsic completions, and editing performance and stability for large projects and solutions. Give the new Razor editor a try and let us know what you think! To enable the new Razor editor, go to Tools > Options > Environment > Preview Features and select Enable experimental Razor editor, and then restart Visual Studio. You can share your feedback with us by creating Razor Tooling issues on GitHub in the ASP.NET Core repo.

Get involved

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

20 comments

Comments are closed. Login to edit/delete your existing comments

  • Igor Shigaev

    First of all, I recommend to avoid word “exciting” when you speak about ridiculous features like “remove unused refs”. IT IS NOT exciting. Just clean up a few LOC, which AFFECTS NOTHING.
    Second, “inheritance margin” is just rotating SAME FUNCTIONALITY available thru popup. You have nothing to do and you duplicate calls of same function??

    Intellisense from MS still in a status “stupidesense”. You cannot even insert full method call when call is obvious! Say, we have File.Close() function. If you write “f.” (and popup appears) and you select “Close”, STUPIDesense inserts just name(!!!). As a result you see “f.Close”, while help could be much better: “f.Close();” – why for 20 years you still cannot do simplistic help??

    That’s why people write extensions – they are tired of stupidity of your team – you do everything except really helpful things. Who is your manager? Why he has no IT education and why your plans always childish?? You have TONS of requests and you’re not able do distinguish REALLY HELPFUL. Your work so pathetic….