Skip to main content

Posts

Showing posts from October, 2026

CSharpier vs dotnet format: C# Code Formatting on .NET 10

Last updated: October 5, 2026 · Tested with CSharpier 1.3.0 (dotnet tool and CSharpier.MSBuild), dotnet format from SDK 10.0.401, Windows 11 Short answer: CSharpier is an opinionated formatter: it rewraps long lines, sorts usings and gives every file the same layout, with almost nothing to configure. dotnet format ships with the SDK and fixes spacing, indentation and code-style rules from .editorconfig , but it never wraps a long line. Use CSharpier for layout and keep dotnet format style and analyzers for code rules. Don't run dotnet format whitespace on top of CSharpier: with a common .editorconfig setting the two tools undo each other and your CI check fails either way. Below are the real before/after files, timings on 3,050 files, and the setup that worked. Install CSharpier (1.x Commands) Install it as a local tool so everyone on the team and the build server use the same version: dotnet new tool-manifest dotnet tool install csharpier dotnet csharpier format . do...

Compile C# at Runtime in .NET: CSharpCodeProvider to Roslyn

Last updated: October 5, 2026 · Tested with .NET 10 (SDK 10.0.401, runtime 10.0.12), Microsoft.CodeAnalysis.CSharp 5.9.0, System.CodeDom 10.0.12, Windows 11 Short answer: CSharpCodeProvider cannot compile code on .NET Core or .NET 5+. Without the System.CodeDom package the code doesn't build (CS1069), and with it, CompileAssemblyFromSource throws PlatformNotSupportedException at runtime. The replacement is Roslyn: add Microsoft.CodeAnalysis.CSharp , build a CSharpCompilation , Emit it to a MemoryStream and load the bytes. Below is the working version on .NET 10, plus the four things that broke when I tried it: the reference list from most older examples fails with CS0012, compiled assemblies never unload unless you use a collectible AssemblyLoadContext , single-file publishing breaks references, and a CancellationToken does not stop code that never returns. The Error: CSharpCodeProvider on .NET Core and .NET 10 This is the classic .NET Framework way to compile C# at r...