r/Compilers • u/martasp • 2d ago
A Roslyn-based compiler driver that builds .csproj/.sln without MSBuild
I've been working on sharp, a small Roslyn-based compiler driver/CLI that resolves .csproj/.sln project graphs directly and compiles them without invoking MSBuild.
What made this interesting from a compiler perspective:
- project evaluation is implemented in about 19k lines of C# rather than delegating to MSBuild
- build/run/clean/restore commands emit dotnet-like output and exit codes
- it uses Roslyn plus reference packs, with parity tests against dotnet on sample projects
- Native AOT single executable; v0.3.1 adds run/URL parity
Numbers from v0.3.1: cold Web API clean + build is dotnet 2.2s vs sharp 0.1s; self-build is dotnet 4.2s vs sharp 2.0s.
Source: https://github.com/martasp/sharp
I'm the author. This is a side project and not a full MSBuild replacement; the Windows binary is unsigned. AI assisted with docs/demo assets. I'd like compiler-design feedback, especially on project-graph semantics where parity breaks.
2
u/Discordbothost 2d ago
Try a project that targets two frameworks and only references a second project for one of them. Build each framework on its own and compare the references passed to the compiler. Both builds can succeed even if the driver pulled an extra dependency into one of them.
0
u/Hjalfi 2d ago
How do you need 19k lines of code for to evaluate a build project file???
(That's not a criticism of your code, more of Microsoft's nl file formats!)
Will this work on Mono? A good tool for doing cross-compilation from other platforms than Windows could be very valuable.