Vermin
Vermin

Reputation: 927

Wix - Launch browser to the .Net framework download URL when .Net framework is not installed

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

Upvotes: 8

Views: 3874

Answers (4)

Dan
Dan

Reputation: 1

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>

Upvotes: 0

Fetchez la vache
Fetchez la vache

Reputation: 5230

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

Upvotes: 2

ZFE
ZFE

Reputation: 324

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.

Upvotes: 0

Vermin
Vermin

Reputation: 927

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&amp;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.

Upvotes: 12

Related Questions