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

你。 提交于 2019-12-06 06:14:25

问题


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;
        }
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/14627507/what-is-the-proper-way-to-download-setup-packages-in-a-wix-custom-managed-bootst

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!