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)
4

5 回答 5

28

只是我的两分钱:

与 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,否则它将不起作用
于 2013-01-09T07:28:13.480 回答
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 中的一个错误

于 2010-08-03T06:33:45.330 回答
2

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

于 2010-07-22T02:26:21.163 回答
1

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

于 2010-08-04T08:55:49.727 回答
1

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

于 2014-01-31T09:59:07.503 回答