Ral*_*don 8 c# msbuild wpf activex .net-4.0
我在使用MSBuild编译C#/ WPF应用程序时遇到问题.
问题如下.我已经使用默认的WPF应用程序创建了一个Visual Studio 2010项目.我创建了一个"老式"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
Run Code Online (Sandbox Code Playgroud)
但是,如果我在构建计算机上以相同的方式编译它会失败,这是一台带有Windows SDK 7.1的Windows Server 2008 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.
Run Code Online (Sandbox Code Playgroud)
如您所见,AxImp.exe工具不接受编译时生成的Interop.AcroPDFLib.dll,因为运行时不匹配.我进一步调查了这个,这里使用的AxImp.exe版本使用.NET 2.0运行时,而Interop.AcroPDFLib.dll文件使用的是.NET 4.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.
Run Code Online (Sandbox Code Playgroud)
为了完整性,如果我在我的机器上运行它,我得到以下(详细)输出:
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".
Run Code Online (Sandbox Code Playgroud)
这里AxImp.exe的路径不同,此版本使用.NET 4.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.
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何强制MSBuild使用4.0版本的AxImp而不是2.0版本?
我找到了解决这个问题的方法.
您必须指定MSBuild应使用的SDK版本.如果添加以下额外的命令行参数,它将起作用(至少在我的情况下).
/p:WindowsSDKVersionOverride=v7.1
Run Code Online (Sandbox Code Playgroud)
显然,MSBuild在默认情况下尝试使用v7.0A版本,而我的buildserver上没有安装.它以某种方式决定忽略所有内容并回退到.NET 2.0路径.我通过删除2.0版AxImp找到了这个.然后它抱怨下面的事情:
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版本覆盖,它将查看正确的注册表项并使用正确的工具版本.
就我而言,我试图在 CI Windows 2012 R2服务器上使用MSBuild编译.csproj(CI 代表持续集成),尽管与此主题最相关的网络问题建议安装Windows SDK,但他们未能准确指出是哪一个。
所以,一开始,我猜他们指的是Windows 10 SDK ,这也是Windows 2012服务器的正确版本。不幸的是,Windows 10 SDK不包含丢失的AxImp.exe SDK 文件。因此,正如你可以想象的那样,我花了很长时间才弄清楚Windows 8.1 SDK是解决这个谜题的关键。
再次希望它对其他人有帮助;-)
| 归档时间: |
|
| 查看次数: |
12795 次 |
| 最近记录: |