Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.net

wix

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

like image 416
Vermin Avatar asked Oct 19 '11 15:10

Vermin


2 Answers

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.

like image 134
Vermin Avatar answered Nov 09 '22 06:11

Vermin


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

like image 34
Fetchez la vache Avatar answered Nov 09 '22 06:11

Fetchez la vache