title: How do you compile a managed dll with mono/mcs targeting a specific framework?
body: <p>I have been using mono/mcs to compile dynamically generated (<a href="https://developers.google.com/protocol-buffers/" rel="nofollow noreferrer">Protocol Buffer</a>) 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).</p>
  
  <p>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.</p>
  
  <p>In the shell script we do something like this:</p>
  
  <pre><code>mono --runtime=v2.0.50727 &lt;stuff&gt;
  
  mcs -langversion:ISO-2 -sdk:2 -r:$unityengine_dll -target:library -out:$output &lt;stuff&gt;
  </code></pre>
  
  <p>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)</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Enviornment: osx sierra 10.12.3, unity 5.5, mono 4.6.2.16</p>