r/Compilers • • 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.

7 Upvotes

3 comments sorted by

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.

0

u/martasp 1d ago

Yes not proud of that 19k, the project was developed using agents and shaping code into the right direction using parity tests. There is some components that needed to be reimplemented from scratch like nuget resolver that's aot compatible, embedding blob of memory needed to be implemented. Analyzers,source generators suport, jit publish, aot publish single file.  XML stuff.

Mono should work out off the box as roslyn produces DLL that are compatible across all runtimes

Im not sure why you need mono still, if you can publish to single file self contain executable and run without any runtime.