我写了一个我一直在使用的WiX自定义MBA,它嵌入了我安装所需的所有安装包(msis,cabs和exes).但是,我现在想制作一个轻量级的Web引导程序,它将下载需要安装的软件包.我以为你可以免费使用底层的WiX引导程序引擎,但我想我错了.
我尝试订阅ResolveSource事件以获取软件包的下载URL并将其下载到本地源位置,但是在此过程中似乎已经太晚了,因为我的安装失败并显示错误"无法解析文件源: "(即使下载成功).
我试过的样本:
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
感谢Rob Mensching在wix-users邮件列表上回答这个问题:
确保提供的URL包(创建最简单但您可以通过编程方式设置它们)然后从ResolveSource调用返回IDDOWNLOAD.
我编辑了我的代码如下:
private void OnResolveSource(object sender, ResolveSourceEventArgs e)
{
if (!File.Exists(e.LocalSource) && !string.IsNullOrEmpty(e.DownloadSource))
e.Result = Result.Download;
}
Run Code Online (Sandbox Code Playgroud)
设置结果以Result.Download指示引导程序引擎下载程序包.无需尝试自己下载文件.