我目前有一个使用 WiX 构建的工作 .msi,它的用户界面我非常满意。唯一缺少的是检测是否缺少 .NET 4.5 以及:
- 使用嵌入式网络设置进行安装,或者
- 引导用户下载 .NET 4.5
我之前使用的安装和部署项目只是将其添加为具有 URL 的 LaunchCondition,并且效果很好。
如何在不借助 Bootstrap 的情况下将其添加到 WiX 安装程序中。据我所知,使用 burn 这样的 Bootstrap 需要重新实现新的用户界面,同样像 dotNetInstaller 这样的工具也会引入新的 UI。
如果我可以让 Bootstrap 不实现它自己的 UI,而是触发 .NET 安装,那么打开也适合我的 msi 当前用户界面。
最佳答案
这是我最终使用的代码...尚未经过全面测试!
产品.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;
}
它对我来说已经足够好了......
关于WiX:提示用户安装 .NET 先决条件的简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12671246/