MsBuild Package
CSharpier can be run when a project is built by installing the CSharpier.MSBuild nuget package
Install-Package CSharpier.MSBuild
By default this will
- In Debug - on build will run csharpierin the project folder to format all files in the project.
- In Release - on build will run csharpier --checkin the project folder to validate that all files in the project have already been formatted.
Properties
Check
You can control when check is used with the following Property
  <PropertyGroup>
    <CSharpier_Check>false</CSharpier_Check>
  </PropertyGroup>
Bypass
You can bypass running CSharpier using the CSharpier_Bypass Property
  <PropertyGroup>
    <CSharpier_Bypass>true</CSharpier_Bypass>
  </PropertyGroup>
dotnet publish -c release -o /app --no-restore /p:CSharpier_Bypass=true
Log Level
You can control the value passed to --log-level with the following Property
  <PropertyGroup>
    <CSharpier_LogLevel>Error</CSharpier_LogLevel>
  </PropertyGroup>
Valid options are:
- None
- Error
- Warning
- Information (default)
- Debug
Target Frameworks
CSharpier.MSBuild will be run with net8.0 or net9.0 if the project targets one of the three frameworks. In cases where the project targets something else (net48, netstandard2.0) CSharpier_FrameworkVersion will default to net8.0
This can be controlled with the following property. This property is required if the csproj is targeting < net8.0 (netstandard2.0, net48, etc) and net8.0 is not installed.
  <PropertyGroup>
    <CSharpier_FrameworkVersion>net8.0</CSharpier_FrameworkVersion>
  </PropertyGroup>