Wix - 在未安装 .Net Framework 时启动浏览器访问 .Net Framework 下载 URL

发布于 2024-12-10 22:42:23 字数 996 浏览 0 评论 0原文

我有一个从安装项目创建的安装程序,并使用 MSBuild 使用找到的方法构建 此处。当我设置构建过程来生成 .msi 文件时,我没有设置项目本身。安装项目的启动条件之一是检查.Net Framework版本4,如果目标计算机上没有安装它,则会向用户显示一个消息框,询问他们是否要访问该URL来下载.Net框架安装文件。如果用户在消息框中选择“是”,则会启动浏览器并加载 URL。好的。安装项目还会检查我们的产品所需的另一个先决条件并执行相同的操作。

我目前正在使用 Wix 重写安装程序,到目前为止,我已经能够解决一些小问题(请记住,我仍然处于整个安装程序的早期阶段)。我已经能够重新创建对 .Net Framework v4.0 和其他必备软件的检查。我还能够显示消息框,询问用户是否要启动浏览器到 URL,以使用自定义 wix 操作下载其他必备软件。

问题

为了对 .Net Framework 执行与旧安装程序相同的操作,我编写了另一个自定义操作来启动浏览器并访问 .Net Framework 下载 URL。我编译了自定义操作和安装程序,并从我的测试机中删除了 .Net 框架。我在测试机器上运行了安装程序,但自定义操作不起作用,这是因为测试机器上不再安装 .Net Framework!

问题

有没有办法重新创建原始安装项目能够检查 .Net 框架的方式,向用户显示消息框,然后启动浏览器到下载 URL(如果用户)选择这样做?我已经能够确定框架是否未安装,只需要一种显示消息框的方法,如果用户选择启动浏览器到特定的 URL,并阻止安装程序继续。

或者

有没有办法在未安装 .Net 框架的计算机上运行自定义操作? (我猜这个问题的答案是否定的!)

一如既往,提前致谢

I have a an installer that is created from a setup project and built using MSBuild using the method found here. Whilst I set up the build process to generate the .msi file, I did not set up the project itself. One of the Launch conditions for the setup project is to check for the .Net framework version 4, and if it is not installed on the target machine, a message box is shown to the user asking if they want to visit the URL to download the .Net framework installation file. Should the user choose "yes" in the message box, then a browser is launched and loads the URL. Nice. The setup project also checks for another prerequisite that our product requires and does the same thing.

I am currently rewriting the installer using Wix and so far I have been able to get around a few minor problems (bearing in mind that I am still in the early stages of the installer as a whole). I've been able to recreate a check for the .Net Framework v4.0 and the other prerequisite software. I have also been able to show the message box asking the user if they want to launch a browser to the URL to download the other prerequisite software using a custom wix action.

The Problem

Wanting to do the same thing for the .Net Framework as the old installer does, I wrote another custom action to launch a browser to the .Net framework download URL. I compiled the custom actions and installer and removed the .Net framework from my test machine. I ran the installer on my test machine and the custom actions did not work, this being due to the .Net Framework no longer being installed on the test machine!!

The Question

Is there a way to recreate the way that the original setup project was able to check for the .Net framework, show the user a message box and then launch a browser to the download URL if the user chooses to do so? I've already been able to establish if the framework is not installed, just need a way to show the message box, launch a browser to the particular URL if the user chooses and prevent the installer from continuing.

or

Is there a way to run custom actions on a machine that does not have the .Net framework installed? (I'm guessing that the answer to this question is going to be no!)

as always, thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

九局 2024-12-17 22:42:23

好的,经过长时间的调查和大量的试验和错误,我能够实现在某些注册表项不存在时启动默认 Web 浏览器的目标。

我首先检查了注册表中所需的条目

<!--Property that indicates whether .Net framework 4.0 is currently installed-->
<Property Id="NETFRAMEWORK40">
  <RegistrySearch Id="NetFramework40" Root="HKLM" Key="Software\Microsoft\NET Framework Setup\NDP\v4\Full" Name="Install" Type="raw" />
</Property>
<!--Property that indicates whether 2007 Office Data Connectivity is currently installed-->
<Property Id="ODCINSTALLED">
  <RegistrySearch Id="CheckODCVersion" Root="HKLM" Key="SOFTWARE\Classes\Installer\Products\000021091D0090400000000000F01FEC" Name="Version" Type="raw" />
</Property>   

,然后将 WixUtilExtension 引用添加到项目中,并设置以下 3 个自定义操作:

<CustomAction Id="SetExec1" Property="WixShellExecTarget" Value="http://go.microsoft.com/fwlink/?LinkID=186913" />
<CustomAction Id="SetExec2" Property="WixShellExecTarget" Value="http://www.microsoft.com/downloads/en/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en" />
<CustomAction Id="LaunchBrowser" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Return="ignore" />

前 2 个自定义操作用于设置将在不同时间使用的 WixShellExecTarget 属性,最后一个自定义操作是使用 WixShellExec 实用程序启动默认浏览器。

然后,我为安装程序 UI 设置了 2 个自定义对话框,其中只有 2 个简单的消息框,其中包含一条短信以及“是”和“否”按钮。以下只是其中一个消息框,因为它们的外观非常相似:

  <Dialog Id="NetFRWDlg" Width="260" Height="95" Title="[ProductName] Installation" NoMinimize="yes">

    <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="40">
      <Text>This setup requires the .NET Framework version 4.0. Please install the .NET Framework and run this setup again. The .NET Framework can be obtained from the web. Would you like to do this now?</Text>
    </Control>

    <Control Id="YesButton" Type="PushButton" X="72" Y="67" Width="56" Height="17" Default="yes" Cancel="yes" Text="[ButtonText_Yes]">
      <Publish Event="DoAction" Value="SetExec1" Order="1">1</Publish>
      <Publish Event="DoAction" Value="LaunchBrowser" Order="2">1</Publish>
      <Publish Event="EndDialog" Value="Exit" Order="3">1</Publish>
    </Control>

    <Control Id="NoButton" Type="PushButton" X="132" Y="67" Width="56" Height="17" Default="no" Cancel="yes" Text="[ButtonText_No]">
      <Publish Event="EndDialog" Value="Exit">1</Publish>
    </Control>

    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="[WarningIcon]" />
  </Dialog>

然后,我将这 2 个对话框添加到 InstallUISequence 表中:

  <InstallUISequence>
    <Show Dialog="NetFRWDlg" After="AppSearch">
      (NOT Installed) AND (NOT NETFRAMEWORK40)
    </Show>
    <Show Dialog="ODCDlg" After="AppSearch">
      (NOT Installed) AND (NOT ODCINSTALLED)
    </Show>
    <Show Dialog="Install_PAGE1" After="CostFinalize" />
  </InstallUISequence>

为了简要概述这一切如何组合在一起,当安装程序启动时,它将检查使用 NETFRAMEWORK40 和 ODCINSTALLED 属性获取所需的注册表。在 InstallUISequence 期间,如果缺少这些注册表,将显示 NetFRWDlg 或 ODCDlg 对话框/消息框。然后,用户可以通过单击对话框/消息框的“是”按钮来选择启动默认浏览器来查看传入的 URL。在此过程中,将执行设置 WixShellExecTarget 属性、启动默认浏览器和退出安装程序的操作顺序。如果用户单击“否”,安装程序将直接退出。

OK, after some lengthy investigation and lots of trial and error I was able to achieve my goal of launching the default web browser when certain registry entries were not present.

I first checked for the required entries in the registries

<!--Property that indicates whether .Net framework 4.0 is currently installed-->
<Property Id="NETFRAMEWORK40">
  <RegistrySearch Id="NetFramework40" Root="HKLM" Key="Software\Microsoft\NET Framework Setup\NDP\v4\Full" Name="Install" Type="raw" />
</Property>
<!--Property that indicates whether 2007 Office Data Connectivity is currently installed-->
<Property Id="ODCINSTALLED">
  <RegistrySearch Id="CheckODCVersion" Root="HKLM" Key="SOFTWARE\Classes\Installer\Products\000021091D0090400000000000F01FEC" Name="Version" Type="raw" />
</Property>   

I then added the WixUtilExtension reference to the project and set the following 3 custom actions up:

<CustomAction Id="SetExec1" Property="WixShellExecTarget" Value="http://go.microsoft.com/fwlink/?LinkID=186913" />
<CustomAction Id="SetExec2" Property="WixShellExecTarget" Value="http://www.microsoft.com/downloads/en/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en" />
<CustomAction Id="LaunchBrowser" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Return="ignore" />

The first 2 custom actions are there to set the WixShellExecTarget property that will be used at different times, the last custom action is to launch the default browser using the WixShellExec utility.

I then set up 2 custom dialogs for my installer UI, just 2 simple message boxes with a short message and Yes and No buttons. The following is just one of the message boxes as they are both very similar in appearance:

  <Dialog Id="NetFRWDlg" Width="260" Height="95" Title="[ProductName] Installation" NoMinimize="yes">

    <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="40">
      <Text>This setup requires the .NET Framework version 4.0. Please install the .NET Framework and run this setup again. The .NET Framework can be obtained from the web. Would you like to do this now?</Text>
    </Control>

    <Control Id="YesButton" Type="PushButton" X="72" Y="67" Width="56" Height="17" Default="yes" Cancel="yes" Text="[ButtonText_Yes]">
      <Publish Event="DoAction" Value="SetExec1" Order="1">1</Publish>
      <Publish Event="DoAction" Value="LaunchBrowser" Order="2">1</Publish>
      <Publish Event="EndDialog" Value="Exit" Order="3">1</Publish>
    </Control>

    <Control Id="NoButton" Type="PushButton" X="132" Y="67" Width="56" Height="17" Default="no" Cancel="yes" Text="[ButtonText_No]">
      <Publish Event="EndDialog" Value="Exit">1</Publish>
    </Control>

    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="[WarningIcon]" />
  </Dialog>

I then added these 2 dialogs into the InstallUISequence table:

  <InstallUISequence>
    <Show Dialog="NetFRWDlg" After="AppSearch">
      (NOT Installed) AND (NOT NETFRAMEWORK40)
    </Show>
    <Show Dialog="ODCDlg" After="AppSearch">
      (NOT Installed) AND (NOT ODCINSTALLED)
    </Show>
    <Show Dialog="Install_PAGE1" After="CostFinalize" />
  </InstallUISequence>

To give a brief outline of how that all comes together, when the installer is started, it will check for the required registries using the NETFRAMEWORK40 and ODCINSTALLED properties. During the InstallUISequence, the NetFRWDlg or ODCDlg dialog/message boxes will be shown if these registries are missing. The user can then choose to launch the default browser to view the passed in URLs by clicking on the Yes button of the dialog/message box. In doing this, the sequence of actions of setting the WixShellExecTarget property, launching the default browser and exiting the installer carry out. If the user clicks No, then the installer will simply exit.

度的依靠╰つ 2024-12-17 22:42:23

正如 ZFE 所提到的,也许最简单的方法是使用引导程序。

拥有托管引导程序应用程序后,您需要做的就是添加 .Net 4.0 作为先决条件。

a) 将文件 WixNetFxExtension.dll 的引用添加到您的引导程序/托管引导程序应用程序项目中

b) 添加以下内容作为您链中的第一个项目..

<PackageGroupRef Id="NetFx40Web"/>

确实是这样!

注意:以上内容将通过互联网下载 .net 4,因此需要可用的互联网连接。更多信息和选项请参见:wixnetfxextension 文档

As ZFE has mentioned, perhaps the simplest way to do this is with a bootstrapper.

Once you have your managed bootstrapper application, all you need to do to add .Net 4.0 as a pre-requisite is..

a) Add a reference to the file WixNetFxExtension.dll into your Bootstrapper / managed Bootstrapper app project

b) Add the following as the first item in your chain..

<PackageGroupRef Id="NetFx40Web"/>

That really is it!

NB The above will download .net 4 over the internet, so an internet connection will be required available. Further info and options here : wixnetfxextension documentation

猫烠⑼条掵仅有一顆心 2024-12-17 22:42:23

您所描述的内容可以通过使用引导程序来完成。生成这些将自动处理必备软件的安装。一些包已包含在 Windows SDK 中(例如 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages),您可以从 msbuild 中使用它们。查看

GenerateBootstrapper

有关创建引导程序可执行文件的 任务(您可以首先构建您的 MSI,然后为其创建引导程序)。

希望您觉得这很有用。

What you have described can be accomplished by using bootstrappers. Generating these will automatically handle installation of prerequisite software. Some packages are already included in Windows SDK (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages for example), and you can use them for example from msbuild. Take a look at the

GenerateBootstrapper

task about to create the bootstrapper executable (you build your msi first then create the bootstrapper for it).

Hope you find this useful.

余生共白头 2024-12-17 22:42:23

我想出了一个与 Vermin 略有不同的解决方案。如果您不想像其他答案所建议的那样使用引导程序应用程序,您可以尝试创建自定义操作和自定义对话框。

您可以使用 WixNetfxExtension,而不是检查 .NET Framework 注册表值。可以通过将“-ext WixNetfxExtension”作为 light.exe 调用的参数传递或使用 Visual Studio WiX 扩展来引用它。然后,您可以使用此属性来检查 .NET Framework "版本号"。在这种情况下,它会检查安装的固件是否为 4.7.2 或更高版本。设置 Sequence="1" 让对话框在安装开始之前出现。对我来说 After="AppSearch" 不起作用。

<PropertyRef Id="WIXNETFX4RELEASEINSTALLED" />

<InstallUISequence>
  <Show Dialog="DotnetFwNotInstalledDialog" Sequence="1">
    <![CDATA[Installed OR (WIXNETFX4RELEASEINSTALLED >= "#461808")]]>
  </Show>
</InstallUISequence>

接下来,设置用于打开下载页面的自定义操作:

<CustomAction Id="SetWixShellExec_DotnetFwLink" Property="WixShellExecTarget" Value="https://dotnet.microsoft.com/download/dotnet-framework/net472" />
<CustomAction Id="LaunchBrowser" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Return="ignore" />

在 UI 元素中,定义自定义对话框。我不知道 Vermin 如何使用控制元素配置图标 (Text="[WarningIcon]")。我使用一个名为“MyIconBinary”的二进制元素来完成此操作,该元素指向图标文件。

<UI>
  <Dialog Id="DotnetFwNotInstalledDialog" Width="260" Height="95" Title="[ProductName] Installation" NoMinimize="yes">
    <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="40">
      <Text>This setup requires the .NET Framework version 4.7.2. Please download and install the .NET Framework 4.7.2 Runtime and run this setup again. Would you like to proceed to the download page?</Text>
    </Control>
    <Control Id="DownloadPageButton" Type="PushButton" X="48" Y="67" Width="106" Height="17" Default="yes" Cancel="yes" Text="Proceed to download page">
      <Publish Event="DoAction" Value="SetWixShellExec_DotnetFwLink" Order="1">1</Publish>
      <Publish Event="DoAction" Value="LaunchBrowser" Order="2">1</Publish>
      <Publish Event="EndDialog" Value="Exit" Order="3">1</Publish>
    </Control>
    <Control Id="ExitButton" Type="PushButton" X="160" Y="67" Width="56" Height="17" Default="no" Cancel="yes" Text="Exit">
      <Publish Event="EndDialog" Value="Exit">1</Publish>
    </Control>
    <Control Id="WarningIcon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Warning" FixedSize="yes" IconSize="32" Text="MyIconBinary" />
  </Dialog>
  
  <Binary Id="MyIconBinary" SourceFile="Resources\MyIcon.ico" />     
</UI>

I came up with a slightly different solution than Vermin. If you don't want to use a bootstrapper application as other answers suggest, you can take the attempt of creating custom actions and a custom dialog.

Instead of checking the .NET Framework registry values you can use the WixNetfxExtension. It can be referenced by passing "-ext WixNetfxExtension" as a parameter on light.exe call or by referencing it using the Visual Studio WiX extension. Then you can use this property to check the .NET Framework "release number". In this case it checks whether the installed FW is 4.7.2 or greater. Setting Sequence="1" let's the dialog appear before the installation starts. For me After="AppSearch" didn't work.

<PropertyRef Id="WIXNETFX4RELEASEINSTALLED" />

<InstallUISequence>
  <Show Dialog="DotnetFwNotInstalledDialog" Sequence="1">
    <![CDATA[Installed OR (WIXNETFX4RELEASEINSTALLED >= "#461808")]]>
  </Show>
</InstallUISequence>

Next, set up the custom actions for opening the download pages:

<CustomAction Id="SetWixShellExec_DotnetFwLink" Property="WixShellExecTarget" Value="https://dotnet.microsoft.com/download/dotnet-framework/net472" />
<CustomAction Id="LaunchBrowser" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Return="ignore" />

In a UI element, define your custom dialog. I couldn't find out how Vermin configured the icon with the control element (Text="[WarningIcon]"). I did it with a binary element called "MyIconBinary" which points to the icon file.

<UI>
  <Dialog Id="DotnetFwNotInstalledDialog" Width="260" Height="95" Title="[ProductName] Installation" NoMinimize="yes">
    <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="40">
      <Text>This setup requires the .NET Framework version 4.7.2. Please download and install the .NET Framework 4.7.2 Runtime and run this setup again. Would you like to proceed to the download page?</Text>
    </Control>
    <Control Id="DownloadPageButton" Type="PushButton" X="48" Y="67" Width="106" Height="17" Default="yes" Cancel="yes" Text="Proceed to download page">
      <Publish Event="DoAction" Value="SetWixShellExec_DotnetFwLink" Order="1">1</Publish>
      <Publish Event="DoAction" Value="LaunchBrowser" Order="2">1</Publish>
      <Publish Event="EndDialog" Value="Exit" Order="3">1</Publish>
    </Control>
    <Control Id="ExitButton" Type="PushButton" X="160" Y="67" Width="56" Height="17" Default="no" Cancel="yes" Text="Exit">
      <Publish Event="EndDialog" Value="Exit">1</Publish>
    </Control>
    <Control Id="WarningIcon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Warning" FixedSize="yes" IconSize="32" Text="MyIconBinary" />
  </Dialog>
  
  <Binary Id="MyIconBinary" SourceFile="Resources\MyIcon.ico" />     
</UI>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文