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

nmd*_*mdr 15 .net wix .net-4.0 wix3.5

我们使用的是WIX 3.5(Build Number 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)
Run Code Online (Sandbox Code Playgroud)

Den*_*els 27

只是我的两分钱:

与Ngm不同,我只需要为.NET 4.0添加supportedRuntime

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

重要:

  1. 不要重命名CustomAction.config
  2. 将CustomAction.config Build Action设置为Content,否则它将不起作用

  • 另外,请确保不要重命名CustomAction.config (8认同)
  • 是! 谢谢!这解决了我的问题.Build Action非常重要!为什么这个问题不是更突出? (3认同)
  • 我很好奇为什么必须将CustomAction.config命名为.在SfxCA.cpp的WiX 3.7源代码中,您可以使用"CustomAction.config"作为硬编码字符串来查看它们.我玩了一下,似乎你可以将你的自定义动作组件,类,函数和命名空间命名为你想要的任何名称,但它必须有一个名为"CustomAction.config"的配置文件设置为Content. (3认同)

nmd*_*mdr 7

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

useLegacyV2RuntimeActivationPolicy="true"
and
have both versions specified:
<supportedRuntime version="v2.0.50727"/>
and
<supportedRuntime version="v4.0"/>
Run Code Online (Sandbox Code Playgroud)

如果只是"<supportedRuntime version="v4.0"/>指定,它不起作用.所以看起来像WIX 3.5 Beta中的一个错误

  • 另外,请确保不要重命名CustomAction.config文件; 否则,设置将不会生效. (2认同)