title: Compile .net 4.0 project on build server with .net 4.5
body: <p>We're having the seemingly common error</p>
  
  <pre><code>Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  </code></pre>
  
  <p>in a project that needs to be compiled against .Net 4.0 but is built on a build server running Windows Server 2012 (with .Net 4.5).  The project is a web application that gets deployed to a web server running 2003, where installing .Net 4.5 isn't an option.  There it runs against "classic" .Net 4.0</p>
  
  <p>From similar questions, we're trying command-line options to MSBuild: </p>
  
  <pre><code>/property:FrameworkPathOverride="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
  </code></pre>
  
  <p>We also tried various combinations of</p>
  
  <pre><code>/property:ReferencePath="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
  /property:NoStdLib=true
  /property:NoCompilerStandardLib=true
  </code></pre>
  
  <p>The reference assemblies (including the .dll files) are in fact installed in that place on the build server.  But when we deploy the website and visit the home page, we get that error.  (Interestingly, on a page reload, the error disappears, and the site operates normally.)  What are the MSBuild parameters necessary to compile against the .Net 4.0 assemblies?</p>
  
  <p><strong>Update</strong>
  I turned on ludicrous-level logging on MSBuild, and I see that apparently it is building against the .Net 4.0 reference assemblies:</p>
  
  <pre><code>Resolved file path is "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
  </code></pre>
  
  <p>and I didn't see any mention of assemblies outside that folder or the build server's working directory.  So it appears to compile properly, but when deployed on the web server, it throws the exception.</p>
  
  <p>As to the exception going away on a page reload, I wonder if that's related to the markup pre-compile step.  We're running aspnet_compile on the build server.  Maybe if there's an exception coming from a generated assembly, the web server will re-compile it.  And the recompiled assembly is fine, because it was created with true .Net 4.0.</p>