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

时间:2010-07-21 10:37:16

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

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

5 个答案:

答案 0 :(得分:27)

只是我的两分钱:

与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,否则无效

答案 1 :(得分:7)

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

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中的一个错误

答案 2 :(得分:2)

打开一个错误,在其清单中调整DTF supportedRuntime元素以支持NETFX 4.0。该错误尚未修复,因此您仍需自行完成。

答案 3 :(得分:1)

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

答案 4 :(得分:1)

感谢这篇不错的帖子。它解决了我的疑问。 在我的情况下错误是我已重命名配置文件,现在将其恢复为原始。