8

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を使用させるにはどうすればよいですか?

4

2 に答える 2

7

この問題の解決策を 1 つ見つけました。

MSBuild が使用する SDK バージョンを指定する必要があります。次の追加のコマンドライン パラメーターを追加すると、機能します (少なくとも私の状況では)。

/p:WindowsSDKVersionOverride=v7.1

どうやら MSBuild はデフォルトで v7.0A バージョンを使用しようとしますが、これは私のビルドサーバーにはインストールされていません。どういうわけか、すべてを無視して .NET 2.0 パスにフォールバックすることを決定します。これは、AxImp の 2.0 バージョンを削除することでわかりました。次に、次のように不平を言います。

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1558,9): error MSB3091: Task failed because "AxImp.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "AxImp.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK. 2) Install Visual Studio 2010. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task.

そのレジストリ キーはビルド サーバーに存在しません。そのため、v7.1 バージョンのオーバーライドを追加すると、正しいレジストリ キーが参照され、正しいツール バージョンが使用されます。

于 2012-05-23T08:00:03.180 に答える
3

Windows 8.1 SDKのインストールに関する問題を解決しました

私の場合、CI Windows 2012 R2サーバー (CI は Continuous Integration の略) でMSBuildを使用して.csprojをコンパイルしようとしていましたが、この件に関する最も関連性の高い Web の問題はWindows SDKをインストールすることを提案していましたが、正確にどれを指し示すことができませんでした.

したがって、最初はWindows 10 SDKを意味すると推測しましたが、これはWindows 2012サーバーの正しいバージョンでもあります。残念ながら、Windows 10 SDKには、欠落しているAxImp.exe SDK ファイルが含まれていません。ご想像のとおり、Windows 8.1 SDKがこのなぞなぞの鍵であることを理解するのにかなりの時間がかかりました。

繰り返しますが、それが他の誰かに役立つことを願っています;-)

于 2016-10-08T00:39:37.003 に答える