.NET Tools
Essential productivity kit for .NET and game developers
ReSharper 2021.3 Starts Early Access Program!
The Early Access Program for ReSharper 2021.3 has started! Get the build today!
Support for Visual Studio 2022 Preview
About a month ago, we published a build with early support for Visual Studio 2022 Preview. According to feedback from our users, ReSharper works faster in the new x64 version of Visual Studio. So far, so good!
Finally, we decided to push this support to the 2021.3 release cycle. The first EAP build of v2021.3 has already had the VS2022 Preview support included. There is no need to download and install a separate build to run ReSharper in VS2022 Preview builds – just select the VS2022 Preview icon in the dotUltimate 2021.3 EAP installer.
Language Support
C# 10
The C# 10 is around the corner, and ReSharper continues adding some of the upcoming features. Today, we are happy to add support for file-scoped namespaces and global usings.
Let’s start with file-scoped namespaces. In addition to supporting the new syntax itself, we’ve added a new Syntax style option (ReSharper | Options | Code Editing | C# | Syntax Style | Code body | Namespaces) which helps you select the desired style. When you choose the style, ReSharper will show you inspections for code that has to be changed to follow the style and suggest the appropriate quick fix for you. You can propagate the fix through the project or even through the whole solution in one click.
If you want to return to the previous Syntax style for the code, there are two context actions: “Convert to file-scoped namespace” and “Convert to block-scoped namespace.”
Now, let’s take a quick look at global usings. ReSharper code analysis is aware of usings marked with the global
keyword and uses these usings to correctly resolve symbols in all the code files in the project. If Solution Wide Error Analysis is ON, ReSharper will highlight global usings which have no usages in the project as unused with a proper quick-fix suggestion to remove the statement. ReSharper will also notify you if the global using
has been placed in the wrong place in the file.
Code Analysis
It is not unusual for people to copy pieces of code from other resources, like stackoverflow.com
. Nowadays, with nullable reference types is available in C#, some of the code samples already include the NRT syntax. But what if you don’t have NRT enabled in your solution? To help you get rid of this syntax after pasting such code to your project, ReSharper has two new quick-fixes: Replace with JetBrains.Annotations attributes and Remove nullable annotations without ‘#nullable’ context.
We’ve added a couple of new quick-fixes and a context action for static local/anonymous functions with closures:
- A quick-fix, Allow closures, to remove
static
modifiers from a local or an anonymous function if it contains closures.
- A quick-fix, Pass closure as a parameter, to lift closures in static local functions to parameters.
- A context action, Pass closure as a parameter, to lift closures in non-
static
local functions to parameters.
There is a new inspection, Simplify string interpolation, with a corresponding quick-fix to replace .PadLeft()
and .PadRight()
method calls with interpolated string placeholders with an alignment expression.
In addition to adding new quick-fixes, we significantly improved the daemon performance for files with huge methods inside:
- Methods with large/nested conditional expressions, tuple expressions, or
switch
expressions. - Methods with lots of type checks when nullable reference types are disabled.
- Methods with a lot of indexer accesses when nullable reference types are enabled.
- Methods with a huge number of closures when nullable reference types are enabled.
Now, the code analysis is completed faster for such files.
Copy Code Reference
This release brings a lot of changes to the Copy FQN feature. First of all, it has a new name, Copy Code Reference. We think this name reflects the meaning of the feature better.
There is also a shortcut, Ctrl+Shift+Alt+C, for calling it directly from the keyboard. Don’t forget to apply the shortcut scheme under ReSharper | Options | Environment | Keyboard | Shortcut Scheme after installing the EAP build to map this shortcut to the action.
We’ve added new functionality if you use Git as a version control system. There are GitHub-related items in the Copy Code Reference pop-up out of the box for projects cloned from GitHub. They generate a proper link to a GitHub repository to share it right away with anyone.
For non-GitHub repositories, you can now add a custom URI template in ReSharper settings. All of these templates will appear in the Copy Code Reference pop-up. The template URI can consist of different predefined placeholders like Current Branch Name
, File Name
, Current Line Number
, etc.
Finally, the pop-up itself has been given a significant facelift. It has a new design, icons, and formatting.
Support for AnalyzerConfig files
Starting with the .NET 5 SDK, you can configure Visual Studio analyzer options with global AnalyzerConfig files. ReSharper 2021.3 EAP can read code style information from these global AnalyzerConfig files and use it to adjust ReSharper rules accordingly.
Language Injections
Now you can mark a function’s parameter, field, or property with the [LanguageInjection] annotation attribute. ReSharper starts to consider a string value of a marked code entity as a code fragment in a specified language. There are the following options of injected languages: CSS, HTML, JavaScript, JSON, or XML. As soon as you add the attribute, you will get proper syntax highlighting, code completion, and other features out of the box inside the string. You need to add the latest preview version of JetBrains.Annotations to your project to use the LanguageInjection attribute.
ReSharper C++
If there’s an expression that can be evaluated during compile-time under the mouse cursor, ReSharper C++ 2021.3 will show the Quick Info tooltip with the evaluation result. For example, you can now consult the message about a failing static_assert
to see what the assertion expression evaluates to, check out the value of a sizeof
or alignof
operator, or any other expression. For a binary expression, you can hover over each operand to get a tooltip with its value or the operator to get a tooltip with the final result:
This EAP build also brings some navigation updates and a number of code inspections to help you adopt the C++20 library features. Check out this blog post for details.
dotMemory
Now, dotMemory can get sampling data about memory allocation based on ETW events. Compared to the traditional (statistical) way of collecting allocation data, sampling is less accurate but provides a number of advantages:
- The sampling allocation data is collected without performance penalties.
- You don’t need to enable collecting this data explicitly, it is always turned on.
- Sampling allocation data can also be collected when you attach the profiler to an already running application.
Note that this feature is available only on Windows.
dotCover
The dotCover .NET global tool gets support for the merge and report commands.
dotPeek
The decompiler now supports the IAsyncDisposable interface.
We’re continuing to improve our support for reading and decompiling single-file apps:
- You can see the content for bundled .json files, for example, the .runtimeconfig.json file.
- You can observe a list of all embedded files with some technical information about the single-file app (header format version and ID) by clicking on the root node in the Assembly Explorer.
- You can extract all the files to a folder using the Extract Bundle Content to Folder action from the context menu.
- You can extract most of the files from the bundle as an external file using the Extract to File action in the context menu.
That’s all for now. Don’t forget to leave your feedback in the comment section below or submit any issues you find to YouTrack.