56

I've been looking at Roslyn for quite some time now, and I'm curious and excited about it. One thing I noticed is that they mentioned that the compiler is re-written in managed code. This raises the question of whether Roslyn is able to run on non-.NET virtual machines, such as Mono.

I would really love to embed C# scripting using Roslyn in my video games, and to use many of their other features in my applications, but I'm wondering if using Roslyn will break the ability for it to run on Mono.

Has anyone tried running Roslyn on Mono? Is it possible? Why or why not?

To clarify, I'm interested in both whether the managed assembly can run on Mono, and whether it can generate assemblies that mono can run.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mirhagk
  • 1,255
  • 3
  • 14
  • 28
  • Are you asking if Roslyn can be executed on mono, or if it produces code that can be run on Mono? The two are independent. My *guess* is that it's no for both though. – Servy Feb 01 '13 at 20:24
  • I edited the original question, I am interested in both. I'm guessing that there is some quirk in it that may make it incompatible as well, but if it is built using managed code, I don't see any major reasons why it wouldn't work. – mirhagk Feb 01 '13 at 20:28
  • 1
    I'm not making this an answer because I have no specific knowledge on this, so I could be wrong. But it being cross platform is certainly not a stated goal of the project, so if it were cross platform it would be "accidentally" so. My guess is that it isn't, however since it probably has some pinvoke code that is windows specific. – David Mason Feb 01 '13 at 20:37
  • @David, the point of Roslyn is that it's entirely managed. It invoking native .dlls would surprise me. – Kirk Woll Feb 01 '13 at 20:44
  • 2
    Roslyn is written in C#. So it is just as cross-platform as C#. It is however currently shipped as a VS extension so work would be needed to separate the two. I would not hold my breath for the kind of license that permits this. – Hans Passant Feb 01 '13 at 20:47
  • 4
    NRefactory 5 - https://github.com/icsharpcode/NRefactory - is the new SharpDevelop / MonoDevelop code analysis tool for C#, and should satisfy your requirements already. It has similar goals to the Roslyn project, though it's not a full compiler. Together with the Mono 'Compiler-as-a-Service' - Mono.CSharp - you should have a viable alternative. Here's one example of code ported from Roslyn to NRefactory recently: http://ermau.com/making-instant-csharp-viable-full-projects/ – Govert Feb 01 '13 at 21:18
  • 1
    @KirkWoll: Being entirely managed is NOT "the whole point" of Roslyn; solving customers problems and producing a strong modern compiler architecture are the point of Roslyn. Being written in managed code was an implementation choice driven by pragmatic concerns such as cost and time to market. Early versions of Roslyn made heavy use of unmanaged libraries, though most of those have been replaced with calls to a modified version of the CCI now. There still may be unmanaged library calls in there for some features. – Eric Lippert Feb 01 '13 at 21:26
  • 2
    @HansPassant: Roslyn might be written in C#, but that is not all there is to being or not being cross-platform. This also depends on the assemblies and BCL types that the Roslyn project references and makes use of. For example, `System.Reflection.Emit` is actually specific to .NET; it is not standardised by the ECMA-335 CLI standard. In this particular case, Mono happens to support this non-standardized functionality, too (IIRC), but it wouldn't strictly have to. – stakx - no longer contributing Feb 01 '13 at 21:29
  • 1
    @Servy I would really, _really_ be surprised if Roslyn produces code that can not run on Mono. Given that current csc produces code that runs on it.. – Lorenzo Dematté Feb 01 '13 at 21:36
  • @Eric, yes, I know, my words were imprecise and wrong. I simply meant to say that it was one of the design goals. – Kirk Woll Feb 01 '13 at 21:37
  • 1
    @KirkWoll: "Do not invoke any native dlls" was never a design goal of Roslyn at any point. – Eric Lippert Feb 01 '13 at 21:39
  • @Eric, good to know. Out of curiosity, is it nonetheless true (that it does not invoke any native dlls)? – Kirk Woll Feb 01 '13 at 21:39
  • 1
    @KirkWoll: It is not true. – Eric Lippert Feb 01 '13 at 21:45

2 Answers2

30

Despite it being the furthest thing from Eric's mind, Roslyn has been released as true Open Source (Apache 2.0) and is in fact now cross-platform.

Miguel de Icaza of Xamarin showed it running on Mono at BUILD.

When Roslyn releases, it will become part of Mono. They are already maintaining a branch at the Mono Git repo.

Justin
  • 8,853
  • 4
  • 42
  • 42
  • 3
    It is truly exciting, and now I'm working on doing some exciting things with it. – mirhagk Apr 20 '14 at 11:35
  • 1
    Just to add on to this, not only is it open source, but so is .NET core framework as well. Find more info here: https://github.com/microsoft/dotnet – mirhagk Nov 19 '14 at 19:54
  • It still has issues on big endian systems, though, at least the last time I tried it on my powerbook. – Wyatt Ward Oct 06 '19 at 18:24
17

As @Govert has already mentioned in a comment, if you want to embed C# scripting capabilities you should simply use the Mono-equivalent library/tool: Mono-Csharp. (Especially because, even if Roslyn could run on Mono, its licence may dictate that you're not allowed to.)

This tool in the Mono world has existed much earlier than Roslyn BTW, and is open source. Here you have even a Microsoft employee blogging about it and uploading it to Nuget:

http://blog.davidebbo.com/2012/02/quick-fun-with-monos-csharp-compiler-as.html

I hope your game will kick ass!

knocte
  • 16,941
  • 11
  • 79
  • 125
  • I'm curious about the other features of Roslyn, not just scripting, which is why I asked about it. OFFTOPIC: Microsoft tends to be very open with .NET stuff lately, isn't Nuget funded by microsoft? – mirhagk Feb 03 '13 at 21:16
  • @mirhagk: As mentioned by Govert in the comments above, the equivalent of Roslyn is NRefactory. See the link here: http://ermau.com/making-instant-csharp-viable-full-projects/ – konrad.kruczynski Feb 04 '13 at 10:08
  • Alright thanks. I'll implement the features using the mono equivalent. – mirhagk Feb 04 '13 at 15:33
  • Is there any place I can find any documentation on Mono-CSharp? (I can't find any beyond a basic introduction). Specifically I'd like to basically compile some source code, and grab a method from it that I can use later (without recompiling) – mirhagk Feb 04 '13 at 22:02
  • So ... Linux build server for your .NET projects? –  May 09 '14 at 19:20