What are JetBrains Annotations – and how to get them?

In our previous blog post, we looked at an example of using JetBrains Annotations. We saw they are an easy way to improve Rider (and ReSharper’s) code analysis, code completion and navigation by adding some simple hints in our code, in the form of attributes. In this post, we’ll look a bit more at the background: what are these annotations? And how do we add them to our source code?

In this series:

we look at how to add JetBrains Annotations to our code, let’s take one step back and look at what they are.

What are JetBrains Annotations?

Rider and ReSharper’s code analysis and inspections are very smart on their own and help find code smells, dead code, potential compile time or run time errors, and more.

We have already seen that we can make this mechanism smarter by telling Rider and ReSharper what we mean. In our previous post, we saw that the ReSharper engine knew we were working with strings, but only we as the author of that code knew these strings were controllers and actions. Code analysis may warn us that a value can be null, but maybe the underlying code never returns null at all. Only one way to tell the engine: annotations. Continue reading

Posted in How-To's | Tagged , , , , | Leave a comment

Improving Rider and ReSharper code analysis using JetBrains Annotations

One of the common questions we often get when meeting our users is this: “Can you show me something I did not know about Rider or ReSharper?” A great example would probably be the use of JetBrains Annotations – an easy way to improve Rider (and ReSharper’s) code analysis and functionality. In the next three blog posts, let’s see what they are and how we can use them to help other developers working with our code!

In this series:

What better way to start this series than to provide just an example, without the nitty-gritty details? Here goes!

A quick example…

Let’s say we are extending ASP.NET MVC’s HtmlHelper with a utility method of our own. The extension method takes three parameters: the HtmlHelper we are extending, a controller name and an action. Here’s the signature:

In our Razor view, it is all too easy to make a mistake when calling this helper method.

Did you spot the issue? We have accidentally mixed up the controller and action parameter. This will not be an issue at compile time, but things would break at run time. Given these are just strings that ASP.NET MVC passes around, making this kind of mistakes is bound to happen. Unless there would be a way to help our tools help us… Continue reading

Posted in How-To's | Tagged , , , , | 7 Comments

Introduce variable, iterate and merge back deconstruction

In our previous post, we’ve looked more closely at and how ReSharper 2018.1 and Rider 2018.1 help maintain consistency when using deconstructing declarations and discards. This time, let’s check out how ReSharper (and Rider) can assist us with introducing variables, iterating and merging back deconstruction when writing new or updating existing C# code.

Introducing variables with deconstruction

Introduce variable is arguably the most used refactoring that has ever existed in ReSharper, and which was available since the very first versions. It allows us to create a new variable, initialize it with a selected expression and optionally replace other occurrences of the same expression with the newly introduced variable.

ReSharper 2018.1 brings an improvement to it: whenever we invoke introduce variable on a tuple or any other expression whose type supports deconstruction, we now get the choice to either introduce a single variable, or to deconstruct the given expression into multiple variables. And if it’s possible to deconstruct value in several ways, ReSharper will show all the alternatives:

Introduce variable demo

Hint: we can introduce a variable in different ways. Via Refactor This… in the Alt+Enter menu, by hitting Ctrl+R,V, by invoking the .var postfix template or by executing the Introduce variable context action.

Continue reading

Posted in How-To's | Tagged , , , , , | Leave a comment

Embrace deconstruction with ReSharper 2018.1

Deconstruction is a great feature that was introduced with C# 7. A while ago, we showed how ReSharper (and Rider) can help generate deconstructors for us. ReSharper 2018.1 adds even more enhanced support to fully embrace the elegance and power of deconstructions with new code styles, quick-fixes, context actions, better refactoring support and more!

In the next two posts, we’ll go over these new features. This first post is dedicated to new code styles. The second part will cover everything else. Let’s dive in!

New code styles

Continue reading

Posted in How-To's | Tagged , , , , | Leave a comment

Navigation improvements in ReSharper 2018.1

Our latest release of ReSharper 2018.1 includes improvements in navigation. We will be looking at several navigation features for Go To that have been improved.

Go To File Member

ReSharper’s ability to move through the members with a file of code has been there since the beginning. We can invoke the ReSharper | Navigate | Go To File Member… command (Alt+\) to view the list of members in the file. We can invoke Alt+\ again and toggle the list to include all members of the current class’s base classes. When we select a member from the list, the caret will be located at that member’s declaration.

Go To File Member

Continue reading

Posted in How-To's | Tagged , , , | 9 Comments

Rider 2018.1 is released!

Please welcome the new spring release of Rider!

Our team has worked hard to make your experience with Rider even smoother and more enjoyable. Download JetBrains Rider 2018.1, or read on for release highlights.
Download JetBrains Rider 2018.1
Continue reading

Posted in How-To's | Tagged , , , , , , , , , , , , , , | 21 Comments

Run Unity tests in Rider 2018.1

In our last couple of posts about new Unity features in Rider 2018.1, we’ve seen that updating our Unity editor plugin to be smarter now allows us to control play mode, and bring the Unity console directly into Rider.

In this series:

The intent here is to reduce the amount of time you spend switching between Rider and the Unity editor. If you’re working with code, let’s stick to the code editor. And so we can single step frames from the debugger, and see log entries directly in the code editor, and Rider makes the stack traces clickable to easily navigate to the right places in your code.

We believe that reducing this context switching will help you concentrate on your game logic, rather than your tooling, which we also hope will help improve the quality of your game or visualisation. But we want to do more than hope, so we’ve now integrated Unity’s unit tests into Rider’s test runner, making it easier than ever to test your code.

This allows you to run tests that interact with Unity’s APIs, and which can step single frames, all from within Rider. And of course, you can explore the results of your Unity specific tests, just like you would normal tests – you can filter by result, and click on stack traces to navigate your code.

Rider test tool window

Continue reading

Posted in How-To's | Tagged , , | 12 Comments

ReSharper Ultimate 2018.1 is available for download

Today we are ready to introduce the first major release of ReSharper Ultimate family for this year – please welcome ReSharper Ultimate 2018.1!

ReSharper Ultimate 2018.1 is available for download

ReSharper gets a significant number of bug fixes (based on more than 260 requests) and a bunch of features and improvements as highlighted below:
Continue reading

Posted in How-To's | Tagged , , , , , , , , , , , , , , , | 30 Comments

Introducing the JetBrains redistributable of MSBuild

Over the past year, JetBrains Rider has become the primary IDE for many .NET developers. Many of our users have been asking us about how they can develop and build their applications without having Visual Studio 2017 installed. The answer is simple on macOS and on Linux, where Mono can be installed. And for .NET Core projects, all we need is the .NET Core SDK which exists for Windows, macOS and Linux.

Things get a bit more interesting when developing and building apps for the full .NET Framework on Windows… Rider will use the tools that are available after installing the Microsoft Build Tools 2017, but these come with one caveat in their license agreement: a validly licensed copy of Visual Studio is required.

Since all we need from the build tools is MSBuild, which is MIT-licensed, we are providing a JetBrains redistributable of MSBuild that can be used freely.

Once downloaded and extracted on our machine, we can configure Rider to use it. From Rider’s settings, under Build, Execution, Deployment | Toolset and Build, then Use MSBuild version, we can specify the Custom MSBuild executable we just extracted.

Set custom MSBuild version in JetBrains Rider

Our redistributable of MSBuild is built from our GitHub fork of the official MSBuild repository. We’re not planning on creating a custom MSBuild version – we just want to provide an MIT-licensed build. In case you have any PR’s, head over to the original repository by Microsoft.

Note that our redistributable excludes some of the proprietary targets files, such as Microsoft.WebApplication.targets. The Mono project does have a stub that could help here.

In summary, to use Rider to develop full .NET framework applications on Windows without the need to have Visual Studio installed:

  1. Download and extract the JetBrains redistributable of MSBuild
  2. Download and install Microsoft .NET Framework Developer Pack 4.5.1 or later
  3. Configure Rider to use a custom MSBuild executable
  4. For any other application types, check the list of prerequisites for using Rider under Windows without Visual Studio

Download Rider now and give it a try with our redistributable of MSBuild. We’d love to hear your feedback!

Update June 15, 2018: Updated binaries to include fix for “The “GetReferenceNearestTargetFrameworkTask” task was not found.” when building app project with reference to library project if .NET Core cross-platform development workload not installed.

Posted in How-To's | Tagged , , , | 16 Comments

Catching up with JetBrains Rider – Talk Recordings

On March 28th we held a special evening of Rider talks at JetBrains Munich office. We would like to thank everybody who was able to join us and make the event a great success.

For those who couldn’t join us in person, we are happy to share the following recorded talks in the playlist below: A Lap Around the Latest Rider 2017.3, .NET Performance Issues and Optimizations in Visual Studio / Roslyn / ReSharper / Rider, and Debugging Tips & Tricks in Rider. Full talk descriptions can be found below.

Continue reading

Posted in How-To's | Tagged , | Leave a comment