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

发布于 2024-10-09 03:46:49 字数 2792 浏览 0 评论 0原文

我有一个 WIX 安装程序,可以在安装过程中执行自定义操作。当我运行 WIX 安装程序并遇到第一个自定义操作时,安装程​​序失败,并且我在 MSI 日志中收到如下错误:

操作开始时间 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.CustomActions:WIXCustomActions System.BadImageFormatException:无法加载文件或程序集“WIXCustomActions”或其依赖项之一。该程序集是由比当前加载的运行时更新的运行时构建的,无法加载。 文件名:“WIX自定义操作” 在 System.Reflection.Assembly._nLoad(AssemblyName fileName、字符串 codeBase、证据 assemblySecurity、程序集位置Hint、StackCrawlMark& stackMark、布尔值 throwOnFileNotFound、布尔值 forIntrospection) 在 System.Reflection.Assembly.nLoad(AssemblyName fileName、字符串 codeBase、证据 assemblySecurity、程序集 locationHint、StackCrawlMark& stackMark、布尔值 throwOnFileNotFound、布尔值 forIntrospection) 在 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef、证据 assemblySecurity、StackCrawlMark& stackMark、布尔值 forIntrospection) 在 System.Reflection.Assembly.InternalLoad(字符串 assemblyString,证据 assemblySecurity,StackCrawlMark& stackMark,布尔值 forIntrospection) 在 System.AppDomain.Load(字符串 assemblyString) 在 Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(会话会话,字符串程序集名称,字符串类名称,字符串方法名称)

...上面的具体问题是“System.BadImageFormatException:无法加载文件或程序集“WIXCustomActions”或其之一该程序集是由比当前加载的运行时更新的运行时构建的,无法加载。”

该错误的措辞似乎表明诸如错误引用的 .NET 框架之类的东西(我在自定义操作及其依赖项中都以 3.5 为目标),但我不知道在哪里进行更改来解决此问题。有什么想法吗?

.... 不确定这是否有帮助,但它是我运行的 CustomActions 包批处理文件,用于创建包含自定义操作函数的 .dll 包:

===============

调用“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 安装程序 xml v3.6\sdk\microsoft.deployment.windowsinstaller.dll" /r:"C:\development\trunk\PortalsDev\csharp\products\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\调试 \eLoyalty.PortalLib.dll" /out:"C:\development\trunk\PortalsDev\csharp\products\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\WIXCustomActions.dll" CustomActions.cs

cd "C:\Program文件 \ Windows Installer XML v3.6 \ SDK"

makefxca "C:\development\trunk\PortalsDev\csharp\products\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\BatchCustomerAnalysisWIXCustomActionsPackage.dll" "c:\program files\windows安装程序 xml v3.6\sdk\x86\sfxca.dll" "C:\development\trunk\PortalsDev\csharp\products\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\WIXCustomActions.dll" customaction.config Microsoft.Deployment .WindowsInstaller.dll

I have a WIX installer that executes Custom Actions over the course of install. When I run the WIX installer, and it encounters its first Custom Action, the installer fails out, and I receive an error in the MSI log as follows:

Action start 12:03:53: LoadBCAConfigDefaults.
SFXCA: Extracting custom action to temporary directory: C:\DOCUME~1\ELOY06~1\LOCALS~1\Temp\MSI10C.tmp-\
SFXCA: Binding to CLR version v2.0.50727
Calling custom action WIXCustomActions!WIXCustomActions.CustomActions.LoadBCAConfigDefaults
Error: could not load custom action class WIXCustomActions.CustomActions from assembly: WIXCustomActions
System.BadImageFormatException: Could not load file or assembly 'WIXCustomActions' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'WIXCustomActions'
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)

... the specific problem from above is "System.BadImageFormatException: Could not load file or assembly 'WIXCustomActions' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

The wordage of that error seems to indicate something like an incorrectly referenced .NET framework or something (I'm targeting 3.5 in both my custom actions and its dependencies), but I can't figure out where to make a change to address this problem. Any ideas?

.... Not sure if this will help but it's the CustomActions package batch file I run to create the .dll package containing the custom action functions:

===============

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

cd "C:\Program Files\Windows Installer XML v3.6\SDK"

makesfxca "C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\BatchCustomerAnalysisWIXCustomActionsPackage.dll" "c:\program files\windows installer xml v3.6\sdk\x86\sfxca.dll" "C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\WIXCustomActions.dll" customaction.config Microsoft.Deployment.WindowsInstaller.dll

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

绝不放开 2024-10-16 03:46:49

BadImageFormatException 很可能表明安装程序中的 x86 和 x64 代码不匹配。

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

The BadImageFormatException is most likely indicating that there is a mismatch between x86 and x64 code in your installer.

If your MSI is 32-bit, make sure the platform target of your custom action project is set to x86, otherwise, if your installer is a 64-bit one, set it to x64.

帅哥哥的热头脑 2024-10-16 03:46:49

我修好了!

问题是在 package.bat 文件期间运行的 csc 实际上是框架的 2.0 版本...

我更改了批处理文件以运行位于 c:\WINDOWS\Microsoft.NET\v3 中的批处理文件。 5\ 来自 v2.0.xxxxx 文件夹中的那个,它现在可以正常工作而不会抛出此错误。

I FIXED IT!

The problem is that the csc that was running during the package.bat file was actually the 2.0 version of the framework...

I changed the batch file to run the one that lives in the c:\WINDOWS\Microsoft.NET\v3.5\ from the one that was in the v2.0.xxxxx folder and it works now without throwing this error..

国粹 2024-10-16 03:46:49

我有一个 WiX v3.11 项目,最近迁移到了 v4。

该错误是在迁移后发生的,因为我忘记将 CustomAction.config 文件添加到自定义操作项目中。

确保您有一个 CustomAction.config 文件并且不要更改其名称!

该文件必须具有 Visual Studio >属性>构建操作设置为内容

下面是该文件的一个典型示例。

<?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>

I had a WiX v3.11 project which I recently moved to v4.

The error was happening after the migration because I forgot to add the CustomAction.config file into the Custom Action project.

Make sure you have a CustomAction.config file and do not change its name!

This file has to have Visual Studio > Properties > Build Action set to Content.

One typical example of this file follows below.

<?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>
甜妞爱困 2024-10-16 03:46:49

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

Check that the launch conditions for the MSI project are showing the correct .net version

贱人配狗天长地久 2024-10-16 03:46:49

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

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

This happens when referenced Custom Action targets framework that is not installed.

So you can either change Target Framework of your custom action project if possible, or check for .NET Framework Version.

凝望流年 2024-10-16 03:46:49

我遇到了类似的问题,但使用的是 .net 4.6
我的自定义 dll 是使用 .net 4.6 构建的,但如果未安装,该包将失败,如上所述。
对我来说,问题是自定义操作在检查 .net 4.6 是否已安装的条件之前运行。所以我将代码更改为:

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

I had a similar problem but with .net 4.6
My custom dll is built with .net 4.6 but if it's not installed the package fails as described above.
The problem for me was that the custom action was running before the condition to check if .net 4.6 is installed. So I changed the code to this:

<Custom Action="MyCustomAction" After="LaunchConditions">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文