Wrapper around CSharpier in order to use it as a dprint plugin for C# and XML code formatting.
- Install dprint 0.61.0 or later
- Run
dprint init - Run
dprint add csharpier
It formats the same files as CSharpier: .cs and .csx files as C#, and .csproj, .props, .targets, .slnx, .config, .xml, .xaml, and .axaml files as XML. Use dprint's "associations" property to change this.
Like CSharpier, it doesn't format generated files (ex. *.g.cs, *.designer.cs, or a C# file starting with an <auto-generated> comment) unless "includeGenerated" is true.
Specify a "csharpier" configuration property in dprint.json if desired:
| Property | CSharpier option | Default |
|---|---|---|
lineWidth |
printWidth |
100 |
indentWidth |
indentSize |
4 for C# and 2 for XML |
useTabs |
useTabs |
false |
newLineKind |
endOfLine |
"auto" |
includeGenerated |
--include-generated |
false |
xmlWhitespaceSensitivity |
xmlWhitespaceSensitivity |
"ignore" for .xaml and .axaml, otherwise "strict" |
The lineWidth, indentWidth, useTabs, and newLineKind properties use the global configuration when not specified, and may be specified for only C# or XML files by prefixing them with csharp. or xml. (ex. "csharp.lineWidth": 120).
The plugin doesn't read CSharpier's configuration files (.csharpierrc or .editorconfig) because dprint plugins don't have access to the file system, so configure it in the dprint configuration file instead.
The plugin is compiled to a Wasm module using NativeAOT-LLVM.
- Run the tests with
dotnet test - Install version 29 of the WASI SDK and set the
WASI_SDK_PATHenvironment variable to its directory. - Run
dotnet publish DprintPluginCSharpier -c Release -r wasi-wasm, which creates DprintPluginCSharpier/bin/Release/net10.0/wasi-wasm/publish/dprint-plugin-csharpier.wasm - Reference the path to the .wasm file in the
"plugins"array of a dprint configuration file to try it out. - Update the generated configuration schema at deployment/schema.json by running
dotnet testwith theUPDATE=1environment variable. - Run the tests that format with the .wasm file in dprint by setting the
DPRINT_CSHARPIER_WASM_PATHenvironment variable to its path and runningdotnet test --filter TestCategory=Wasm. These use thedprinton the path or the executable at theDPRINT_PATHenvironment variable.
dprint only provides the WASI preview 1 functions to Wasm plugins, so the module must not import anything else. DprintPluginCSharpier/ILLink.Substitutions.xml and the feature switches in the project file keep code that would import other functions out of the module.
Run the release workflow, which bumps the version and pushes a tag. The CI workflow then publishes the GitHub release and the npm package for the tag.
{ // etc... "csharpier": { "lineWidth": 120, "xml.indentWidth": 4 } }