【问题标题】:WIX Custom Actions built for .Net Framework 4.0 does not work? Ways to resolve?为 .Net Framework 4.0 构建的 WIX 自定义操作不起作用?解决方法?
【发布时间】:2010-07-21 10:37:16
【问题描述】:

我们使用的是 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)

【问题讨论】:

  • 您是否期望 2.0 CLR 能够加载 4.0 程序集并执行它?

标签: .net .net-4.0 wix wix3.5


【解决方案1】:

只要我的两分钱:

与 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,否则将不起作用

【讨论】:

  • 还要确保不要重命名 CustomAction.config
  • 是的!谢谢!这解决了我的问题。构建动作非常重要!为什么这个问题没有更突出?
  • 我很好奇为什么 CustomAction.config 必须如此命名。在 SfxCA.cpp 中的 WiX 3.7 源代码中,您可以看到它们使用“CustomAction.config”作为硬编码字符串。我玩过,似乎您可以将自定义操作程序集、类、函数和命名空间命名为您想要的任何名称,但它必须有一个名为“CustomAction.config”的配置文件设置为内​​容。
  • 感谢您提到您不应该(不能)重命名“CustomAction.config”,这是解决我的问题的关键。
  • 只是为了记录,文件必须命名为 CustomAction.config 并且 Build Action 设置为 Content。如果您不小心将其删除,然后重新添加配置文件,则必须重命名。
【解决方案2】:

好吧,我们终于解决了问题,我们不得不设置:

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

如果只指定"&lt;supportedRuntime version="v4.0"/&gt;,则它不起作用。所以看起来像 WIX 3.5 Beta 中的一个错误

【讨论】:

  • 感谢帮助。虽然在我的情况下,我不需要 v2 supportedRuntime 元素。刚刚 v4 工作正常。
  • 另外,请确保不要重命名 CustomAction.config 文件;否则设置不会生效。
【解决方案3】:

存在一个错误,用于调整其清单中的 DTF supportedRuntime 元素以支持 NETFX 4.0。该错误尚未修复,因此您仍需要自己修复。

【讨论】:

    【解决方案4】:

    除了来自 Ngm 的解决方案之外,我们还必须将托管自定义操作类库的目标框架设置回 .NET 2.0 才能正常工作。

    【讨论】:

      【解决方案5】:

      感谢这篇好文章。它解决了我的查询。 在我的情况下,错误是我已重命名配置文件,现在将其恢复为原始文件。

      【讨论】:

      • 这是我唯一需要做的事情,而且它奏效了。不需要任何其他东西。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 2011-02-11
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      相关资源
      最近更新 更多