Introduction
Microsoft has released codeformatter on
GitHub. This tool uses Roslyn which can be used to format C# project code automatically as per
guidelines . With the source code format we will have better readability and maintainability of a code.
Prerequisite:
In order to run this tool we need to have Microsoft Build Tools 2015 Preview installed on machine and it comes as part of Visual Studio 2015 preview.
Usage:
The tool is fairly simple to use. Just we have to pass project or solution file to codeformatter exe so that it converts all files according to prescribed coding style.
Example:
codeformatter.exe MySamplePorject.csproj
codeformatter.exe MySamplePorject.sln
We can pass more parameters to CodeFormatter like below
$ .\CodeFormatter.exe
CodeFormatter <project or solution> [<rule types>] [/file <filename>]
<rule types> - Rule types to use in addition to the default ones.
Use ConvertTests to convert MSTest tests to xUnit.
<filename> - Only apply changes to files with specified name.
<configs> - Additional preprocessor configurations the formatter
should run under.
<copyright> - Specifies file containing copyright header.
How it is differ from Ctrl-K-D:
It is similar to Ctrl-K-D option in visual studio but additionally it has removing old copyright headers or adding new ones which Ctrl+K+D doesn't support.
References: