Early Access Program How-To's Tips & Tricks

ReSharper Command-Line Tools – Cross-Platform and Global Tools

We’re often asked how ReSharper and Rider relate to build servers, and how their features can be utilized in CI/CD environments. There are actually quite a few tools bundled in free packages – namely ReSharper.CommandLineTools or dotCover.CommandLineTools – that can help to continuously monitor and improve our codebase. In this post, we will discuss the ReSharper tools, which include:

  • InspectCode – runs code analysis to find and report code issues
  • DupFinder – identifies semantically duplicated code fragments
  • CleanupCode – reformats code to make it consistent

Check out our blog posts that put a more practical focus on InspectCode, DupFinder, and CleanupCode:

ReSharper InspectCode Report in TeamCity

But now, without further ado, let’s get to the real news: these tools are now cross-platform, and can be used as .NET global tools!

Running Cross-Platform

Many of our tools already run cross-platform. With the latest 2020.2 EAP package, the ReSharper command-line tools also contain 3 shell scripts to run on Linux and macOS:

./inspectCode.sh MySolution.sln
./cleanupCode.sh MySolution.sln
./dupFinder.sh MySolution.sln

Note that as a result of going cross-platform, we’ve also updated the parameters to use double-dashes instead of single slashes.

Usage as Global Tools

A while ago, the .NET Core SDK introduced .NET Global Tools, which can be installed to be globally available like other shell commands. Targeting netcoreapp3.1, we’ve prepared a new jb global tool shipped with the JetBrains.ReSharper.GlobalTools package that lets us easily invoke InspectCode, CleanupCode, or DupFinder without needing to worry about where the tools are located:

dotnet tool install JetBrains.ReSharper.GlobalTools --global --version 2020.2.0-*
jb inspectcode MySolution.sln
jb dupfinder MySolution.sln
jb cleanupcode MySolution.sln

In a build script, we can also install it as a local tool to keep the operating system clean from unnecessary modifications. Using a tool manifest file, we can execute the following locally:

# One-time locally
dotnet new tool-manifest
dotnet tool install JetBrains.ReSharper.GlobalTools --version 2020.2.0-*

# In the build script
dotnet tool restore
dotnet jb inspectcode MySolution.sln

Without a tool manifest, we can use the --tool-path parameter:

dotnet tool install JetBrains.ReSharper.GlobalTools --tool-path ./ --version 2020.2.0-*
./jb inspectcode MySolution.sln

We’d also like to say thanks to John for this suggestion!

Please let us know if you have any questions or feedback, and give ReSharper or Rider a try if you haven’t already done so. They’ll definitely make it easier to fix code smells and generally clean up code!

image description