这是我最终使用的代码......尚未经过全面测试!
产品.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;
}
它对我来说足够好......