WIX CustomAction加载CLR 4.0而不是2.0

Dvl*_*878 3 custom-action wix dtf

我正在尝试编写ac#自定义操作并使用.Net 2,但是我似乎无法让事情发挥作用.我相信MSI使用的是错误的CLR版本.我在日志文件中看到MSI正在调用我的CA的几行(如果我注释掉我的CA,则不会出现换行符):

SFXCA: Binding to CLR version v4.0.30319. 
Run Code Online (Sandbox Code Playgroud)

我的自定义操作似乎没有加载(假设我没有看到任何日志消息).我正在使用Wiz 3.6.3014.0.是否支持或Windows Installer是否只使用计算机上可用的最新运行时?

谢谢

Chr*_*ter 6

使用WiX创建C#自定义操作项目时,默认情况下会创建名为CustomAction.config的XML文件.此文件的目的是指示sfxca.dll运行代码时要使用的CLR版本.此文件的默认实现如下所示:

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

</configuration>
Run Code Online (Sandbox Code Playgroud)

基本上,使用.NET 2.0/3.0/3.5(所有CLR 2.0)编写的CA是一个很好的做法,因为你可能遇到只安装了4.0的机器.通常你的代码应该对4.0有效,如果没有,我会修复它.

或者,您可以将配置文件更新为仅允许在2.0上运行,然后将所需的检查放入安装程序,以确保安装了此版本的CLR.