代码之家  ›  专栏  ›  技术社区  ›  coder_bro

为.Net Framework 4.0构建的WIX自定义操作不起作用?如何解决?

  •  15
  • coder_bro  · 技术社区  · 15 年前

    我们使用wix3.5(内部版本号1811),并使用visualstudio2008构建了一个自定义操作,目标框架为.net3.5。在我们使用VisualStudio2010和.NET4.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)
    
    5 回复  |  直到 15 年前
        1
  •  28
  •   Denys Wessels    11 年前

    只要我的两分钱:

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

    重要提示:

    1. 将CustomAction.config构建操作设置为Content,否则它将无法工作
        2
  •  7
  •   coder_bro    15 年前

    好吧,我们终于解决了问题,我们必须设置:

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

    如果只是 "<supportedRuntime version="v4.0"/> 如果已指定,则不起作用。看起来像是wix3.5beta中的一个bug

        3
  •  2
  •   Rob Mensching    15 年前

        4
  •  1
  •   menty    15 年前

        5
  •  1
  •   Anna    11 年前

    谢谢你的好帖。它解决了我的问题。 在我的情况下,错误是我已经重命名配置文件,现在恢复到原来的。