WIX CustomAction加载CLR 4.0而不是2.0

时间:2012-06-18 21:40:11

标签: wix custom-action dtf

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

SFXCA: Binding to CLR version v4.0.30319. 

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

由于

1 个答案:

答案 0 :(得分: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>

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

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