Learn What’s New in .NET Productivity
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.
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.
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.
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.
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.
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.
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.
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.
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 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.
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.
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.
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.
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.
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.
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.
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.
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.