WIXv4: How can we download and install other executables with custom ProgressDlg?
Image by Jessiqua - hkhazo.biz.id

WIXv4: How can we download and install other executables with custom ProgressDlg?

Posted on

Are you tired of the limitations of WIXv4 when it comes to downloading and installing other executables? Do you want to customize the installation process with a progress dialog that reflects your brand’s identity? Look no further! In this article, we’ll take you on a step-by-step journey to download and install other executables with a custom ProgressDlg in WIXv4.

Understanding the Problem

By default, WIXv4 provides a built-in mechanism for downloading and installing executables using the <ExePackage> element. However, this approach has its limitations. What if you want to:

  • Download executables from a custom URL?
  • Show a custom progress dialog that matches your brand’s visual identity?
  • Handle errors and exceptions more elegantly?

The good news is that WIXv4 provides a way to overcome these limitations using custom actions and a custom ProgressDlg. But before we dive into the solution, let’s take a step back and understand the requirements.

Requirements

To follow this tutorial, you’ll need:

  • WIXv4 installed on your system
  • A basic understanding of WIXv4 syntax and concepts
  • A custom executable that you want to download and install
  • A custom ProgressDlg design (we’ll provide an example later)

The Solution

The solution involves creating a custom action that downloads the executable, a custom ProgressDlg to display the progress, and a few tweaks to the WIXv4 script. Let’s break it down into smaller steps.

Step 1: Create a Custom Action

First, we need to create a custom action that downloads the executable. We’ll use a C# custom action to achieve this. Create a new C# class library project in Visual Studio and add the following code:

using System;
using System.IO;
using System.Net;

namespace CustomAction
{
    public class DownloadExecutable
    {
        [CustomAction]
        public static ActionResult DownloadExecutable(Session session)
        {
            string executableUrl = session["EXECUTABLE_URL"];
            string downloadPath = session["DOWNLOAD_PATH"];

            using (WebClient client = new WebClient())
            {
                client.DownloadFile(executableUrl, downloadPath);
            }

            return ActionResult.Success;
        }
    }
}

In this code, we’re using the WebClient class to download the executable from the specified URL to the specified download path. We’re also using the Session object to retrieve the executable URL and download path from the WIXv4 script.

Step 2: Create a Custom ProgressDlg

Next, we need to create a custom ProgressDlg that displays the progress of the executable download. We’ll use a simple Windows Forms application to achieve this. Create a new Windows Forms App project in Visual Studio and add the following code:

using System;
using System.Windows.Forms;

namespace CustomProgressDlg
{
    public partial class ProgressDlg : Form
    {
        public ProgressDlg()
        {
            InitializeComponent();
        }

        public void SetProgress(int progress)
        {
            progressBar.Value = progress;
        }
    }
}

In this code, we’re creating a simple form with a progress bar. We’ll use this form to display the progress of the executable download.

Step 3: Modify the WIXv4 Script

Now, let’s modify the WIXv4 script to use our custom action and ProgressDlg. Add the following code to your WIXv4 script:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="MyProduct" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="PUT-GUID-HERE">
    <Package InstallerVersion="200" Compressed="yes" />
    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <CustomAction Id="DownloadExecutable" BinaryKey="CustomAction" DllEntry="DownloadExecutable" Execute="deferred" />
    <Binary Id="CustomAction" SourceFile="CustomAction.CA.dll" />

    <UI>
      <Dialog Id="ProgressDlg" Width="370" Height="270" Title="Download and Install">
        <Control Id="ProgressBar" Type="ProgressBar" Width="300" Height="20" X="35" Y="50" ProgressBar="yes" />
      </Dialog>
    </UI>

    <InstallExecuteSequence>
      <Custom Action="DownloadExecutable" Before="InstallFinalize" />
    </InstallExecuteSequence>

    <Property Id="EXECUTABLE_URL" Value="https://example.com/myexecutable.exe" />
    <Property Id="DOWNLOAD_PATH" Value="[TempFolder]\myexecutable.exe" />
  </Product>
</Wix>

In this code, we’re:

  • Defining a custom action called “DownloadExecutable” that references our custom action DLL
  • Defining a custom ProgressDlg with a progress bar
  • Associating the custom action with the ProgressDlg using the <InstallExecuteSequence> element
  • Setting the executable URL and download path as properties

Putting it all Together

Now that we have all the pieces in place, let’s put them together. Compile your custom action DLL and ProgressDlg application, and add them to your WIXv4 project. Build and run your WIXv4 installer, and you should see the custom ProgressDlg displaying the progress of the executable download.

Troubleshooting Tips

If you encounter any issues during the installation process, here are some troubleshooting tips:

  • Check the WIXv4 logs for errors and exceptions
  • Verify that the custom action DLL and ProgressDlg application are correctly referenced in the WIXv4 script
  • Ensure that the executable URL and download path are correctly set as properties

Conclusion

In this article, we’ve shown you how to download and install other executables with a custom ProgressDlg in WIXv4. By using custom actions and a custom ProgressDlg, you can overcome the limitations of the built-in <ExePackage> element and create a more customized installation experience for your users. Remember to follow the instructions carefully and troubleshoot any issues that may arise.

If you have any questions or need further assistance, feel free to ask in the comments below. Happy installing!

Related Articles
WIXv4: How to create a custom bootstrapper
WIXv4: How to create a custom installer UI

Frequently Asked Question

Get answers to your burning questions about WIXv4 and custom ProgressDlg!

Can I download and install other executables with custom ProgressDlg in WIXv4?

Yes, you can! WIXv4 allows you to download and install other executables using the `util:DownloadUrl` and `ScheduleReboot` elements. You can also create a custom ProgressDlg to display the installation progress.

How do I specify the executable to download and install?

You can specify the executable to download and install using the `File` element and setting the `Source` attribute to the URL of the executable. For example: ``

How do I create a custom ProgressDlg?

To create a custom ProgressDlg, you’ll need to define a `Dialog` element with a `ProgressDlg` element inside. You can then customize the appearance and behavior of the dialog using the various attributes and elements available. For example: ``

Can I show custom messages during the installation process?

Yes, you can show custom messages during the installation process using the `TextStyle` and `String` elements. For example: ``

How do I handle errors during the installation process?

You can handle errors during the installation process using the `Error` element and specifying the error message and behavior. For example: `Hello, there was an error installing my executable.MyExitDlg`