What is the proper way to download setup packages in a WiX custom managed bootstrapper application?

StackOverflow https://stackoverflow.com/questions/14627507

  •  06-03-2022
  •  | 
  •  

Question

I wrote a WiX custom MBA that I have been using which embeds all of the setup packages (msis, cabs and exes) I need for my installation. However I would now like to make a lightweight web bootstrapper which will download the packages that need to be installed. I thought you would get that for free with the underlying WiX bootstrapper engine, but I guess I was wrong.

I tried subscribing to the ResolveSource event to get a package's download url and download it to the local source location, but it seems like at that point it's too late in the process as my installation fails with an error "Failed to resolve source for file: " (even though the download is successful).

Sample of what I tried:

private void OnResolveSource(object sender, ResolveSourceEventArgs e)
{  
    string localSource = e.LocalSource;
    string downloadSource = e.DownloadSource;

    if (!File.Exists(localSource) && !string.IsNullOrEmpty(downloadSource))
    {
        try
        {
            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(e.DownloadSource, e.LocalSource);
            }
        }

        catch (ArgumentNullException ex)
        {
            e.Result = Result.Error;
        }

        catch (WebException ex)
        {
            e.Result = Result.Error;
        }
    }
}
Was it helpful?

Solution

Thanks to Rob Mensching answering this on the wix-users mailing list:

Make sure your packages of URLs provided (authored is easiest but you can programmatically set them all) then return IDDOWNLOAD from the ResolveSource call.

I edited my code as follows:

private void OnResolveSource(object sender, ResolveSourceEventArgs e)
{
    if (!File.Exists(e.LocalSource) && !string.IsNullOrEmpty(e.DownloadSource))
        e.Result = Result.Download;
}

Setting the result to Result.Download instructs the bootstrapper engine to download the package. No need to try to download the file myself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top