MSBuildを使用したC#/WPFアプリケーションのコンパイルに問題があります。
問題は次のとおりです。デフォルトのWPFアプリケーションを使用してVisualStudio2010プロジェクトを作成しました。コントロールを使用して表示する「昔ながらの」Windowsフォームユーザーコントロールを作成しました。このユーザーコントロールが行う唯一のことは、Adobe ReaderのActiveXコントロール(AcroPDFLibを使用)を使用してPDFドキュメントを表示することです。
これは、次のコマンドを使用して、Windows 7(64ビット)とVS2010がインストールされているローカルマシンで完全にコンパイルされます。
>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe AcroPDFTest.sln /p:Configuration=Debug /t:Rebuild /verbosity:d
ただし、ビルドマシン(WindowsSDK7.1を搭載したWindowsServer2008 R2マシン)で同じ方法でコンパイルすると失敗します。次に、次のエラーが発生します(詳細な出力を含む)。
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.
ご覧のとおり、AxImp.exeツールは、実行時の不一致のため、コンパイル時に生成されたInterop.AcroPDFLib.dllを受け入れません。これをさらに調査したところ、ここで使用されているAxImp.exeのバージョンは.NET 2.0ランタイムを使用していますが、Interop.AcroPDFLib.dllファイルは.NET4.0を使用しています。
>"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.
完全を期すために、これを自分のマシンで実行すると、次の(詳細な)出力が得られます。
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".
ここでは、AxImp.exeのパスが異なり、このバージョンは.NET4.0ランタイムを使用します。
>"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.
だから私の質問は:MSBuildに2.0バージョンの代わりに4.0バージョンのAxImpを使用させるにはどうすればよいですか?