在 WiX 自定义托管引导程序应用程序中下载安装程序包的正确方法是什么? [英] What is the proper way to download setup packages in a WiX custom managed bootstrapper application?

查看:13
本文介绍了在 WiX 自定义托管引导程序应用程序中下载安装程序包的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个我一直在使用的 WiX 自定义 MBA,它嵌入了我安装所需的所有安装包(msis、cabs 和 exe).但是,我现在想制作一个轻量级的网络引导程序,它将下载需要安装的软件包.我以为您可以使用底层的 WiX 引导程序引擎免费获得它,但我想我错了.

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.

我尝试订阅 ResolveSource 事件以获取包的下载 url 并将其下载到本地源位置,但此时似乎为时已晚,因为我的安装失败并显示错误无法解析源for file: "(即使下载成功).

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).

我尝试过的示例:

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

推荐答案

感谢 Rob Mensching 在 wix-users 邮件列表上回答这个问题:

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

确保提供了您的 URL 包(编写是最简单的,但您可以以编程方式将它们全部设置)然后从ResolveSource 调用.

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

将结果设置为 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.

这篇关于在 WiX 自定义托管引导程序应用程序中下载安装程序包的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆