WIX安装程序自定义操作:“由比当前加载的运行时更新的运行时构建,因此无法加载。”

4
我有一个WIX安装程序,执行安装过程中的自定义操作。当我运行WIX安装程序并遇到第一个自定义操作时,安装程序失败了,并在MSI日志中收到以下错误消息:
“Action start 12:03:53: LoadBCAConfigDefaults. SFXCA:将自定义操作提取到临时目录:C:\ DOCUME〜1 \ ELOY06〜1 \ LOCALS〜1 \ Temp \ MSI10C.tmp-\ SFXCA:绑定到CLR版本v2.0.50727 调用自定义操作WIXCustomActions!WIXCustomActions.CustomActions.LoadBCAConfigDefaults 错误:无法从程序集WIXCustomActions加载自定义操作类WIXCustomActions.CustomActions System.BadImageFormatException:无法加载文件或程序集'WIXCustomActions'或其某个依赖项。该程序集是由比当前加载的运行时更新的运行时构建的,因此无法加载。 文件名:'WIXCustomActions' 在System.Reflection.Assembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,Assembly locationHint,StackCrawlMark& stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection) 在System.Reflection.Assembly.nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,Assembly locationHint,StackCrawlMark& stackMark,Boolean throwOnFileNotFound,Boolean forIntrospection) 在System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,Evidence assemblySecurity,StackCrawlMark& stackMark,Boolean forIntrospection) 在System.Reflection.Assembly.InternalLoad(String assemblyString,Evidence assemblySecurity,StackCrawlMark& stackMark,Boolean forIntrospection) 在System.AppDomain.Load(String assemblyString) 在Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(Session session,String assemblyName,String className,String methodName)”
上述具体问题是“System.BadImageFormatException:无法加载文件或程序集'WIXCustomActions'或其某个依赖项。该程序集是由比当前加载的运行时更新的运行时构建的,因此无法加载。”
这个错误的措辞似乎表明类似于.NET框架引用不正确之类的问题(我在自定义操作和其依赖项中都针对3.5),但我无法找出在哪里进行更改以解决此问题。有什么想法吗?
...不确定这是否有帮助,但这是我运行的CustomActions软件包批处理文件,用于创建包含自定义操作函数的.dll包:
===============
call“C:\ Program Files \ Microsoft Visual Studio 10.0 \ VC \ vcvarsall.bat”
@echo on
cd“C:\ development \ trunk \ PortalsDev \ csharp \ production \ Installers \ WIX \ customactions \ PAServicesWIXCustomActions”

csc /target:library /r:"C:\program files\windows installer xml v3.6\sdk\microsoft.deployment.windowsinstaller.dll" /r:"C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\eLoyalty.PortalLib.dll" /out:"C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\WIXCustomActions.dll" CustomActions.cs

进入目录 "C:\Program Files\Windows Installer XML v3.6\SDK"

运行 makesfxca 命令,生成自解压缩文件 "BatchCustomerAnalysisWIXCustomActionsPackage.dll" ,并将其与 "Microsoft.Deployment.WindowsInstaller.dll" 和 "customaction.config" 一起打包到 "WIXCustomActions.dll" 中,使用的 sfxca.dll 文件路径为 "c:\program files\windows installer xml v3.6\sdk\x86\sfxca.dll"。

6个回答

1

BadImageFormatException 很可能表示您的安装程序中存在 x86 和 x64 代码不匹配的问题。

如果您的 MSI 是 32 位的,请确保自定义操作项目的平台目标设置为 x86,否则,如果您的安装程序是 64 位的,则将其设置为 x64。


1
感谢您的回答,但是它是32和32...我在同一台机器上编译并运行了它!我正在使用WIX 3.6和VS 2010。 - Rimer
你的操作系统是64位的吗?你的MSI设置为x86进程运行了吗?你的.NET项目的平台目标是什么? - Dirk Vollmar
.NET项目的目标框架为3.5 Framework;操作系统为32位,MSI设置为以平台活动(x86)运行。自定义操作项目也针对.NET 3.5进行了定位。 - Rimer

1

我解决了!

问题在于package.bat文件运行时使用的csc实际上是2.0版本的框架...

我将批处理文件更改为运行位于c:\WINDOWS\Microsoft.NET\v3.5\目录下的文件,而不是v2.0.xxxxx文件夹中的文件,现在它可以正常工作而不会抛出错误。


7
你的回答不够清晰,package.bat是什么?我也遇到了同样的错误,但我的项目中没有这样的.bat文件。 - user145400

0

我遇到了类似的问题,但是与 .net 4.6 相关。 我的自定义 dll 是使用 .net 4.6 构建的,但如果没有安装它,包将会像上面描述的那样失败。 对我来说,问题在于自定义操作在检查是否安装了 .net 4.6 的条件之前运行。因此,我将代码更改为:

<Custom Action="MyCustomAction" After="LaunchConditions">

0

检查MSI项目的启动条件是否显示了正确的.NET版本


0

当引用的自定义操作目标框架未安装时,就会发生这种情况。

因此,如果可能的话,您可以更改自定义操作项目的目标框架,或者检查.NET Framework版本


0
我有一个WiX v3.11项目,最近我将其迁移到了v4。
迁移后出现了错误,因为我忘记将CustomAction.config文件添加到自定义操作项目中。
确保你有一个CustomAction.config文件,并且不要更改它的名称!
这个文件的Visual Studio > Properties > Build Action必须设置为Content
下面是一个典型的文件示例。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">

    <!--
      Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
      the custom action should run on. If no versions are specified, the chosen version of the runtime
      will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.

      WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
      problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
      only the version(s) of the .NET Framework runtime that you have tested against.

      Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.

      In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
      by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".

      For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
    -->

    <supportedRuntime version="v4.0" />
    <supportedRuntime version="v2.0.50727"/>

  </startup>

<!--
  Add additional configuration settings here. For more information on application config files,
  see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->

  <!-- The snippet below was transplanted from the app.config file. -->
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接