【问题标题】:WiX: Simple way to prompt user to install .NET pre-requisiteWiX:提示用户安装 .NET 先决条件的简单方法
【发布时间】:2012-10-01 10:06:14
【问题描述】:

我目前有一个使用 WiX 构建的工作 .msi,它有一个我非常满意的用户界面。唯一缺少的是检测是否缺少 .NET 4.5 以及:

  • 使用嵌入式网络设置安装它,或者
  • 将用户引导至 .NET 4.5 下载

我之前使用的安装和部署项目只是将它添加为带有 URL 的 LaunchCondition,并且运行良好。

如何在不借助引导程序的情况下将其添加到 WiX 安装程序。据我所知,使用像 burn 这样的引导程序需要重新实现一个新的用户界面,同样像 dotNetInstaller 这样的工具也会引入一个新的 UI。

如果我可以让引导程序不实现它自己的 UI,而是触发 .NET 安装,那么打开 msi 的当前用户界面,这也适用于我。

【问题讨论】:

标签: wix


【解决方案1】:

我想给你一个答案,我相信人们会拒绝投票,但我也想保留 MSI 的 UI,所以我添加了这个代码来启动硬件密钥的 exe 安装程序。我知道这违反了 MSI 最佳实践,但这是我唯一打算打破的。希望这会有所帮助。

<Property Id="WixShellExecTarget" Value="[#myapplication.exe]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />

然后我通过单击按钮运行自定义操作。您可以生成一个带有下载按钮的错误对话框并通过它链接它。一点也不优雅,但它适用于我和我的公司作为一种解决方法..:)

编辑:您还可以通过单击按钮使用此代码来启动下载 URL,Value 属性具有完整的超链接。

【讨论】:

  • 谢谢,这是一个小宝石,我运行了两个硬件密钥 exe,还运行了一个单独的 URL,它适用于所有三个..:)
  • 感谢您的回答。我选择了其他东西,但很高兴人们发现它有用:)
  • 没问题,我也使用了自定义操作,直到找到这个。除非确实需要,否则尝试减少自定义操作,因此这是一个很好的解决方法。很高兴你成功了。
【解决方案2】:

这是我最终使用的代码...尚未经过全面测试!

产品.wxs:

    ...
    <!-- custom actions -->
    <InstallUISequence> <!-- .NET dialog runs only in UI mode and we skip it on the wrong platform so platform condition test is triggered later -->
      <?if $(var.Platform) = x64 ?>
      <Custom Action="InstallCA" Before="LaunchConditions">(NOT REMOVE~="ALL") AND NOT (Installed OR NETFRAMEWORK45) AND VersionNT64</Custom>
      <?elseif $(var.Platform) = x86 ?>
      <Custom Action="InstallCA" Before="LaunchConditions">(NOT REMOVE~="ALL") AND NOT (Installed OR NETFRAMEWORK45) AND NOT VersionNT64</Custom>
      <?endif?>
    </InstallUISequence>
  </Product> <!-- end product -->

  <Fragment>
    <Binary Id="WiXCustomActions" SourceFile="$(var.WiXCustomActions.TargetDir)$(var.WiXCustomActions.TargetName).CA.dll" />
    <CustomAction Id="InstallCA" BinaryKey="WiXCustomActions" DllEntry="DotNetCheck" Execute="firstSequence" />
  </Fragment>

以及自定义操作(在 C# 类库中):

    [CustomAction]
    public static ActionResult DotNetCheck(Session session)
    {
        try
        {
            MessageBoxResult result = System.Windows.MessageBox.Show(
                "This application requires that .NET Framework 4.5 is installed." + Environment.NewLine
                + "Would you like to open the Microsoft download page for" + Environment.NewLine + ".NET Framework 4.5?",
                ".NET Framework 4.5 is missing",
                MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);
            switch (result)
            {
                case MessageBoxResult.Yes:
                    System.Diagnostics.Process.Start("http://go.microsoft.com/fwlink/p/?LinkId=245484");
                    break;
            } //else just finish
        }
        catch (Exception ex)
        {
            session.Log("Error. " + ex.Message);
            System.Windows.MessageBox.Show("Error:" + ex.Message);
        }
        return ActionResult.SkipRemainingActions;
    }

它对我来说足够好......

【讨论】:

    【解决方案3】:

    还有一件重要的事情,当你将创建这个 DLL 库时

    以及自定义操作(在 C# 类库中):

    需要添加下一个引用:

    using WixSharp    
    using Microsoft.Deployment.WindowsInstaller
    using System.Windows.Forms
    

    还将“MessegeBoxResult”替换为“DialogResult”,并且 MessegeBox 应该从类 System.Windows.Forms 中获取

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 2013-02-10
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多