CleanupCode Command-Line Tool
CleanupCode is a free cross-platform command-line tool that can perform code cleanup to instantly eliminate code style violations in a project or solution and ensure a uniform code base.
Download ReSharper Command Line Tools. Use the selector next to the Download button to choose your operating system.
Unzip the command line tools package in any directory.
Ensure that the downloaded .zip file is 'unblocked' before extracting: right-click the file, select Properties and click Unblock. Failure to do this will cause the .NET framework to load the application in partial trust, which means it won't load or run correctly.
Build the target solution. Make sure that you use the proper build configuration.
Run the following command:cleanupcode.exe YourSolution.sln
Alternatively, you can install ReSharper command line tools as .NET Core tools and run CleanupCode with the
Configure CleanupCode with DotSettings
If you have previously worked on the target solution with ReSharper, you may have already configured code style settings. If so, CleanupCode will find your custom settings in .DotSettings files and apply them.
CleanupCode will read the following preferences from DotSettings files:
Code formatting rules ( and )
Syntax styles ( )
If you want to configure CleanupCode on a CI server, you can make all configurations locally with ReSharper, save the settings to the Solution Team-Shared layer, and then commit the resulting YourSolution.sln.DotSettings file in the solution directory to your VCS. CleanupCode on the server will find and apply these settings.
As an alternative, you can specify a path to a shared .DotSettings file (which will override settings in other settings files, if any) through the
Configure CleanupCode with EditorConfig and Clang-Format
ReSharper lets you use EditorConfig to define any of its code style preferences that are available in in the ReSharper's Options dialog. You can find names and descriptions of supported EditorConfig properties in the EditorConfig reference.
As for Clang-Format, ReSharper will only apply the supported Clang-Format options.
It is important to note that any code style property defined in an .editorconfig file will override the same property defined in ReSharper settings in the scope where this .editorconfig file applies. Formatting properties defined in Clang-Format will override both ReSharper settings and EditorConfig settings.
Configure CleanupCode with command-line parameters
--profile— a code cleanup profile that lists cleanup tasks to execute.
There are two more built-in profiles —Built-in: Reformat Code, which will only applies code formatting preferences and Built-in: Reformat & Apply Syntax Style, which applies code formatting preferences and code syntax styles. To use one of these profiles or any custom profile, pass the profile name via the
--profileparameter, for example:
--profile="Built-in: Reformat Code" YourSolution.sln.
--include/--exclude— relative path(s) or wildcards that define the files to include/exclude during the cleanup. If both
--excludeare defined and cover the same set of files,
--excludewill have higher priority.
To specify multiple paths or wildcards, separate them with the semicolon or use the
--include/--excludeparameters several times.
--verbosity— by default, CleanupCode only displays information messages in the log. Use this parameter to change the amount of information written to the log by the following levels (the order is from less to more detailed):
[OFF, FATAL, ERROR, WARN, INFO, VERBOSE, TRACE].
For example, if something goes wrong with CleanupCode, you can contact ReSharper support and share a log file with all TRACE messages:
--verbosity=TRACE > [path_to_log_file].
--caches-home— lets you specify a custom location for the data that CleanupCode caches. By default, the %LOCALAPPDATA% directory is used, unless there are settings files, in which case the one specified there is used. This parameter can be helpful if you want to use a fast SSD disk for the cache or if you want to store all your build processing data in a single place.
--config— these options allow you to pass the parameters described above with a configuration file. The first option will create a configuration file according to the current parameters; the second option is used to load the parameters from this file.
--debug (-d)— use this option to add execution details of CleanupCode to the output. If you have problems with CleanupCode, these details will be helpful when contacting the support team.
Parameters that control ReSharper settings
--settings— by default, CleanupCode will override its default settings with ReSharper settings from the 'Solution team-shared' layer SolutionName.DotSettings, if it exists. If necessary, you can use this parameter to specify another .DotSettings file, which will override all other settings. For example,
-dsl— disables specified settings layers. Accepted values:
--no-buildin-settings— suppresses settings from global, solution, and project setting layers. Equivalent to
--disable-settings-layers: GlobalAll; GlobalPerProduct; SolutionShared; SolutionPersonal; ProjectShared; ProjectPersonal
MSBuild. Possible problems and solutions
When CleanupCode receives the target solution file, it needs to create a list of files to be cleaned up and initialize a number of properties, such as language version. CleanupCode uses MSBuild to get this information from project files.
In most cases, CleanupCode automatically finds the proper MSBuild executable for the target solution. But there might be problems that prevent auto-detection, such as when the version of the solution runtime does not match the version of the installed .NET SDK.
If CleanupCode yields an error such as
The current .NET SDK does not support targeting .NET Core 3.0. or
The SDK 'Microsoft.NET.Sdk' specified could not be found., you need to specify the correct SDK or runtime using additional parameters. If you work with .NET, MSBuild is already installed on your machine, and often more than one installation exists, so you have to provide one that fits the target solution.
In most cases you will have to add just one parameter —
--dotnetcore. In complicated cases, for example, many different installations on the machine or when using a custom version of MSBuild, you may need other parameters:
When you specify
--dotnetcoresdk, CleanupCode will try to use MSBuild from .NET Core SDK and ignore others. For example, if you have several installations of MSBuild v 16.0 on your machine and specify a path to .NET Core installation with
--dotnetcore, CleanupCode will use .NET Core MSBuild from the specified installation. When
--dotnetcore is not specified, CleanupCode will look into the solution directory, try to find global.json, and use the SDK version specified there. If nothing is found, the latest available SDK version will be used.
Project references. Possible problems and solutions
MSBuild is also used by CleanupCode to resolve symbols from referenced projects and assemblies. There are two project properties that allow using different references depending on the environment:
Configuration. If the environment where you run CleanupCode differs from the environment where the project was last built, you can receive errors such as:
Can't resolve reference XXX: Reference wasn't resolved by MsBuild or
Could not resolve this reference. Could not locate the assembly "XXX".
If you get such an error, check the output to see whether there is a mismatch in build configurations. For example
In the above, you can see that the platform specified in the project file is
x86, but the tool is running in a 64-bit mode. To fix this, specify the target platform and the configuration explicitly with the
CleanupCode supports the following languages: