3

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

SFXCA: Binding to CLR version v4.0.30319. 

我的自定义操作似乎没有加载(假设因为我没有看到任何日志消息)。我正在使用 Wiz 3.6.3014.0。这是否受支持,或者 Windows 安装程序是否仅使用机器上可用的最新运行时?

谢谢

4

1 回答 1

9

当您使用 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 的机器。一般来说,您的代码应该适用于 4.0,如果不适用,我会修复它。

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

于 2012-06-18T23:37:46.337 回答