Adds autoformat tooling to MSBuild projects via dotnet format.
-
In a .NET project, add a package reference to
DarkPatterns.Build.Autoformat. -
Set
PrivateAssets="All"on the PackageReference to prevent the Autoformat library from being referenced in the build outputs. -
Configure your
.editorconfigto match rules for your .NET coding standard. See Microsoft's .editorconfig documentation for more details.
For solution-wide settings:
-
Add the reference to
DarkPatterns.Build.Autoformatvia theDirectory.Build.propsto ensure autoformat is set for all projects. -
Place the
.editorconfigin the same folder as your Directory.Build.props. Alternatively, be sure to include your.editorconfigin theEditorConfigFilesitem.
-
Ensure you have a
.gitattributesfile that sets the default line ending for a git checkout to prevent end-of-line changes on first build after switching branches. For example:* text=auto eol=lf
| Name | Decription | Default |
|---|---|---|
| EnforceCodeStyleInBuild | See Microsoft's documentation for EnforceCodeStyleInBuild | true |
| AnalysisLevel | See Microsoft's documentation for AnalysisLevel | latest-Recommended |
| LintSkipDotnet | Skips the Lint target entirely if set to true |
false |
| LintEnforceNoChanges | When true, will not update files but instead will cause an error if not already in the correct format |
true if Configuration is Release |
| DotnetFormatArgs | Additional arguments for the dotnet format command. |
Empty |
Runs before build. Executes dotnet format for the project being built if LintEnforceNoChanges is not true, otherwise dotnet format --verify-no-changes.
Runs before Lint. May be used prior to linting any project to run prerequisite build steps on a solution-wide basis.