Dot-Net

為 .Net Framework 4.0 建構的 WIX 自定義操作不起作用?解決方法?

  • May 26, 2014

我們使用 WIX 3.5(內部版本號 1811)並建構了使用 Visual Studio 2008 建構的自定義操作,目標框架為 .Net 3.5。這曾經很好用,直到我們使用 Visual Studio 2010 和目標框架為 .Net 4.0 建構了自定義操作。

WIX 無法呼叫自定義操作,我們得到的錯誤是:

 SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI69BD.tmp-\
   SFXCA: Binding to CLR version v2.0.50727
   Calling custom action SomeCompany.SomeProduct.InstallerPlugin!SomeCompany.SomeProduct.InstallerPlugin.XYZProductCustomAction.ABCMethod
   Error: could not load custom action class SomeCompany.SomeProduct.InstallerPlugin.XYZProductCustomAction from assembly: SomeCompany.SomeProduct.InstallerPlugin

   System.BadImageFormatException: Could not load file or assembly 'SomeCompany.SomeProduct.InstallerPlugin' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

   File name: 'SomeCompany.SomeProduct.InstallerPlugin'
      at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
      at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
      at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
      at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
      at System.AppDomain.Load(String assemblyString)
      at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(Session session, String assemblyName, String className, String methodName)

好吧,我們終於解決了問題,我們必須設置:

useLegacyV2RuntimeActivationPolicy="true"
and
have both versions specified:
<supportedRuntime version="v2.0.50727"/>
and
<supportedRuntime version="v4.0"/>

如果只是"<supportedRuntime version="v4.0"/>指定,它不起作用。所以看起來像 WIX 3.5 Beta 中的一個錯誤

只是我的兩分錢:

與 Ngm 不同,我只需要為 .NET 4.0 添加supportedRuntime

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v4.0" />
 </startup>
</configuration>

重要的:

  1. 不要重命名 CustomAction.config
  2. 將 CustomAction.config Build Action 設置為 Content,否則它將不起作用

引用自:https://stackoverflow.com/questions/3298304