- Home /
How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity?
I have been using mono/mcs to compile dynamically generated (Protocol Buffer) code into managed DLLs for use in Unity. As of Unity 5.5, it looks like it will no longer load DLLs compiled against the 4.0 framework (I believe it wants 2.0 or 3.5).
I have seen how to do this in MonoDevelop or Visual Studio, but I would like to do this on the command line because the protobuf code is dynamically generated so it makes it much easier to use a shell script to compile.
In the shell script we do something like this:
mono --runtime=v2.0.50727 <stuff>
mcs -langversion:ISO-2 -sdk:2 -r:$unityengine_dll -target:library -out:$output <stuff>
When we do this, we've always had warnings come up in the following form (which makes it look like the target runtime is not actually being set correctly). Even with these warnings, in Unity 5.4.x it would load the dll fine and compile. In Unity 5.5+ it doesn't seem to be able to load the dll and dies on compilation errors (where it doesn't find things which should be defined in the dll)
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v4.0.30319
No framework specified; defaulting to 4.0.30319.42000
What do we need to change? I have been playing around with the --runtime, --langversion, and -sdk -lib options of mono/mcs to no avail. What should these be set to for compiling for unity? Have also tried using both a current up-to-date version of mono to compile and also the mono that comes with Unity, both have the same issue.
Environment: osx sierra 10.12.3, unity 5.5, mono 4.6.2.16
Answer by jerome-lacoste · Sep 06, 2017 at 04:30 PM
Did you manage to fix your issue? We are able to make editor plugins compiled as DLLs using the following call:
mcs -r:#{reference_string} -target:library -sdk:2 -out:my.dll #{files}
Using Unity 5.6, and mcs from MonoBleedingEdge bundled with Unity.