title: AxImp .NET4.0 runtime mismatch
body: <p>I have a problem with the compilation of a C#/WPF application using MSBuild. </p>
  
  <p>The problem is the following. I have created a Visual Studio 2010 project with a default WPF application. I created an "old fashioned" Windows Forms usercontrol which I display using the  control. The only thing this usercontrol does is displaying a PDF document using the ActiveX control from Adobe Reader (with AcroPDFLib).</p>
  
  <p>This compiles perfectly on my local machine that has Windows 7 (64 bit) and VS2010 installed using the following command.</p>
  
  <pre><code>&gt;C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe AcroPDFTest.sln /p:Configuration=Debug /t:Rebuild /verbosity:d
  </code></pre>
  
  <p>However, it fails if I compile it the same way on our build machine, which is a Windows Server 2008 R2 machine with Windows SDK 7.1. It then comes up with the following error (including verbose output):</p>
  
  <pre><code>Using "ResolveComReference" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
  Task "ResolveComReference"
    Creating new cache file at "obj\x86\Debug\AcroPDFTest.csproj.ResolveComReference.cache".
    Resolving COM reference for item "AcroPDFLib" with a wrapper "tlbimp".
    Determining dependencies of the COM reference "AcroPDFLib".
    Resolving COM reference dependency "00020430-0000-0000-c000-000000000046" version 2.0.
    Resolved COM reference dependency "00020430-0000-0000-c000-000000000046" version 2.0: "obj\x86\Debug\Interop.stdole.dll"
    Type '_IAcroAXDocShimEvents' imported.
    Type 'AcroPDF' imported.
    Type 'IAcroAXDocShim' imported.
    Type 'AdobeSPOpenDocuments' imported.
    Type 'ISPOpenDocuments' imported.
    Resolved COM reference for item "AcroPDFLib": "obj\x86\Debug\Interop.AcroPDFLib.dll".
    Resolving COM reference for item "AxAcroPDFLib" with a wrapper "aximp".
    Determining dependencies of the COM reference "AxAcroPDFLib".
    C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\AxImp.exe "C:\Program Files (x86)\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll" /out:obj\x86\Debug\AxInterop.AcroPDFLib.dll /rcw:obj\x86\Debug\Interop.AcroPDFLib.dll 
  AXIMP : AxImp error : The assembly '[snip]\obj\x86\Debug\Interop.AcroPDFLib.dll' failed to load with this error: Could not load file or assembly 'file:///[snip]\obj\x86\Debug\Interop.AcroPDFLib.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.. [[snip]\AcroPDFTest.csproj]
    The command exited with code -1163019603.
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1558,9): warning MSB3283: Cannot find wrapper assembly for type library "AxAcroPDFLib". [[snip]\AcroPDFTest.csproj]
  Done executing task "ResolveComReference" -- FAILED.
  </code></pre>
  
  <p>As you can see, the AxImp.exe tool does not accept the compile-time generated Interop.AcroPDFLib.dll, because of a runtime mismatch. I investigated this further and the version of AxImp.exe that is being used here uses the .NET 2.0 runtime, while the Interop.AcroPDFLib.dll file is using .NET 4.0:</p>
  
  <pre><code>&gt;"C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\AxImp.exe" /?
  Microsoft (R) .NET ActiveX Control to Windows Forms Assembly Generator
  [Microsoft .Net Framework, Version 2.0.50727.5456]
  Copyright (c) Microsoft Corporation.  All rights reserved.
  </code></pre>
  
  <p>For completeness, if I run this on my machine I get the following (verbose) output:</p>
  
  <pre><code>Using "ResolveComReference" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
  Task "ResolveComReference"
    Creating new cache file at "obj\x86\Debug\AcroPDFTest.csproj.ResolveComReference.cache".
    Resolving COM reference for item "AcroPDFLib" with a wrapper "tlbimp".
    Determining dependencies of the COM reference "AcroPDFLib".
    Resolving COM reference dependency "00020430-0000-0000-c000-000000000046" version 2.0.
    Resolved COM reference dependency "00020430-0000-0000-c000-000000000046" version 2.0: "C:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll"
    Type '_IAcroAXDocShimEvents' imported.
    Type 'AcroPDF' imported.
    Type 'IAcroAXDocShim' imported.
    Type 'AdobeSPOpenDocuments' imported.
    Type 'ISPOpenDocuments' imported.
    Resolved COM reference for item "AcroPDFLib": "obj\x86\Debug\Interop.AcroPDFLib.dll".
    Resolving COM reference for item "AxAcroPDFLib" with a wrapper "aximp".
    Determining dependencies of the COM reference "AxAcroPDFLib".
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\AxImp.exe "C:\Program Files (x86)\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll" /out:obj\x86\Debug\AxInterop.AcroPDFLib.dll /rcw:obj\x86\Debug\Interop.AcroPDFLib.dll 
    Generated Assembly: [snip]\obj\x86\Debug\AxInterop.AcroPDFLib.dll
    Resolved COM reference for item "AxAcroPDFLib": "obj\x86\Debug\AxInterop.AcroPDFLib.dll".
  Done executing task "ResolveComReference".
  </code></pre>
  
  <p>Here the path of the AxImp.exe is different, and this version does use the .NET 4.0 runtime:</p>
  
  <pre><code>&gt;"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\AxImp.exe" /?
  Microsoft (R) .NET ActiveX Control to Windows Forms Assembly Generator
  [Microsoft .Net Framework, Version 4.0.30319.269]
  Copyright (c) Microsoft Corporation.  All rights reserved.
  </code></pre>
  
  <p>So my question is: How can I force MSBuild to use the 4.0 version of AxImp instead of the 2.0 version?</p>