Search code examples
c#monocompiler-as-a-service

C# Compiler-as-a-Service: Mono.CSharp vs Microsoft.CSharp


I am looking to replace certain reflection-based parts of our code with ones that perform better using dynamic runtime compilation. Looking around I saw that both Mono and Microsoft have separate Compiler-as-a-Service solutions: Mono.CSharp and Microsoft.CSharp.

With the risk of asking an opinion-based question, I'm wondering how these two compare?

As far as I can tell from a very superficial initial investigation, they both generally provide CAAS capabilities. I was able to compile a "Hello World" class using Microsoft.CSharp and execute it. And although I didn't do the same thing with the Mono one yet, I'm assuming it could do the same.

Does anyone have any experience with either or both and can comment on the issue?


Edit: I am not asking about a comparison of Mono's C# and Microsoft's C# - we are already familiar with and using both. The question is specifically about the two CAAS (Compiler-as-a-Service) solutions.

CAAS isn't (yet anyway) a standard part of the .NET runtime, i.e there is no System.Compile namespace yet. The two solutions Mono.CSharp and Microsoft.CSharp are separate non-standard CAAS solutions for C#. Their interfaces are very different and hence the question.

Mono's compiler service

Microsoft's compiler service


Edit #2: Completely forgot about Roslyn (thanks to @Lex Li)


Solution

  • Microsoft.CSharp as it's now (.net 4.5) is API used by C# compiler to emit bindings for C# dynamic expressions. Therefore it's C# compiler but very limited. The same API (dll) is implemented by both .NET and Mono so you can compile on .NET and run on Mono and vice-versa.

    Mono.CSharp is evaluator style API to Mono C# compiler. It allows you to compile any C# text-like code (expressions, statement, type declarations, etc) and execute it. It relies on System.Reflection and System.Reflection.Emit heavily.

    Neither of these have any relation to CodeDom.