CSharpier 0.10.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global CSharpier --version 0.10.0                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local CSharpier --version 0.10.0                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CSharpier&version=0.10.0                
nuke :add-package CSharpier --version 0.10.0                

CSharpier

CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules. The printing process was ported from prettier but has evolved over time.
CSharpier provides a few basic options that affect formatting and has no plans to add more. It follows the Option Philosophy of prettier.

Work In Progress

CSharpier is still in active development and the rules it uses to format code are not yet finalized and will change over time.

If you can live with the fact that the formatting will be changing over time, it is safe to use. In addition to a steadily growing set of unit tests; csharpier is tested against ~60k c# files from a range of public repositories to validate it does not result in the lose of any source code.

Features

  • It is fast. It can format a solution of ~11,000 files in ~30 seconds.
  • It supports validating the syntax of the code it produces to ensure the only changes made were whitespace and line breaks.
  • It formats c# ⇐ 9.0 - c# 10 coming soon

Try it out at Playground

Before

public class ClassName {
    public string ShortPropertyName {
        get;
        set; 
    }

    public void LongUglyMethod(string longParameter1, string longParameter2, string longParameter3) { 
        this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }
}

After

public class ClassName
{
    public string ShortPropertyName { get; set; }

    public void LongUglyMethod(
        string longParameter1,
        string longParameter2,
        string longParameter3
    )
    {
        this.LongUglyMethod(
            "1234567890",
            "abcdefghijklmnopqrstuvwxyz",
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        );
    }
}

Installation

dotnet tool install -g csharpier

Basic Usage

Run csharpier from the directory you wish to format to recursively format all .cs files

dotnet csharpier .

Run csharpier on a specific file

dotnet csharpier /src/UglyUnformattedFile.cs

MsBuild Package

If you prefer to have csharpier run when a project is built, you can use the CSharpier.MSBuild nuget package

Install-Package CSharpier.MSBuild

Documentation

Command Line Interface
Configuration File
Editors and CI/CD
Integrating with Linters/Formatters
Ignoring Files
ChangeLog
MSBuild Package

Contributing

See Development Readme

Join Us Discord

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.28.2 248,522 4/26/2024
0.28.1 50,293 4/16/2024
0.28.0 62,495 4/7/2024
0.27.3 211,234 2/18/2024
0.27.2 90,625 1/28/2024
0.27.1 21,173 1/24/2024
0.27.0 54,856 1/15/2024
0.26.7 140,420 12/16/2023
0.26.6 15,255 12/14/2023
0.26.5 44,113 12/10/2023
0.26.4 35,409 12/2/2023
0.26.3 64,889 11/23/2023
0.26.2 54,897 11/16/2023
0.26.1 38,128 11/9/2023
0.26.0 14,531 11/6/2023
0.25.0 508,960 6/25/2023
0.24.2 131,618 5/5/2023
0.24.1 22,489 4/26/2023
0.24.0 1,361 4/26/2023
0.23.0 112,688 3/6/2023
0.22.1 132,401 1/18/2023
0.22.0 7,310 1/15/2023
0.21.0 146,540 11/29/2022
0.20.0 107,664 10/3/2022
0.19.2 26,627 9/15/2022
0.19.1 70,650 8/27/2022
0.19.0 72,009 8/15/2022
0.18.0 93,782 6/13/2022
0.17.0 47,013 5/23/2022
0.16.0 79,239 3/26/2022
0.15.1 28,478 2/14/2022
0.15.0 1,436 2/9/2022
0.14.0 5,571 1/22/2022
0.13.0 3,592 1/3/2022
0.12.0 4,681 11/30/2021
0.11.1 989 11/15/2021
0.10.0 1,186 10/18/2021
0.9.9 1,380 8/23/2021
0.9.8 992 7/27/2021
0.9.7 503 6/26/2021
0.9.6 521 6/12/2021
0.9.5 812 6/1/2021
0.9.4 430 5/24/2021
0.9.3 411 5/18/2021
0.9.2 444 5/6/2021
0.9.1 345 5/5/2021
0.9.0 398 4/23/2021
0.8.9 330 4/12/2021
0.8.8 511 3/27/2021
0.8.7 358 3/22/2021
0.8.6 346 3/16/2021
0.8.5 350 3/12/2021
0.8.4 375 3/8/2021
0.8.3 438 3/8/2021
0.8.2 363 2/27/2021
0.8.1 449 2/22/2021