【问题标题】:How to use property values within downloadurl in wix如何在 wix 的 downloadurl 中使用属性值
【发布时间】:2022-12-15 12:52:32
【问题描述】:

我需要根据用户输入在 wix burn 中创建下载 URL 以下载 MSI 包。当我在创建 .exe 包时将它们作为输入时,我正在设置如下属性并将属性设置到这些变量中没有问题。

<Variable Name="PROTOCOL" Value="!(wix.Protocol)" bal:Overridable="yes"/>
<Variable Name="SOURCE" Value="!(wix.Source)" bal:Overridable="yes"/>

但问题是当我在 MsiPackage 元素的 downloadUrl 属性中使用这些属性时,不会采用这些属性的实际值。 Burn 只需将它们识别为 [PROTOCOL] 和 [SOURCE]。以下是我的 MsiPackage 元素。

<MsiPackage Id="SSCE" Name="SQL Server Compact Edition" SourceFile="../PackageRepo/SQLCE 3.5/SSCERuntime-ENU.msi" Cache="no" Vital="yes" Compressed="no" ForcePerMachine="yes" Permanent="yes"
      DownloadUrl="[PROTOCOL]://[SOURCE]/PackageRepo/SQLCE 3.5/SSCERuntime-ENU.msi" InstallCondition="(NOT SSCERuntimeVersion) AND (NOT SSCERuntimeServicePackLevel)"/>

因为这个文件没有下载。那么谁能告诉我如何使用 MsiPackage 元素的 downloadUrl 属性中的属性值。

【问题讨论】:

    标签: c# wix windows-installer bootstrapper burn


    【解决方案1】:

    您面临的问题是,这些属性不会在运行时扩展(或者如果它们在哪里,它们究竟应该在什么时候扩展?

    有点老套的例子:

    <MsiPackage Id="SSCE" Name="SQL Server Compact Edition" SourceFile="../PackageRepo/SQLCE 3.5/SSCERuntime-ENU.msi" Cache="no" Vital="yes" Compressed="no" ForcePerMachine="yes" Permanent="yes"
          DownloadUrl="PackageRepo/SQLCE 3.5/SSCERuntime-ENU.msi" InstallCondition="(NOT SSCERuntimeVersion) AND (NOT SSCERuntimeServicePackLevel)"/>
    

    所以只需将 DownloadUrl 用于后者的相对路径,并使用 OnResolveSource 事件为引擎设置正确的 downloadUrl:

    private void OnResolveSource(object sender, ResolveSourceEventArgs ea)
    {
      if( ea.PackageOrContainerId.Equals("SSCE")
      {
        if (!File.Exists(ea.LocalSource) )
        {
        if (string.IsNullOrEmpty(ea.DownloadSource) && !string.IsNullOrEmpty(CurrentUrl))
        {
          // get the relative path
          var dlUrl = $"{Engine.StringVariables["PROTOCOL"]}://{Engine.StringVariables["SOURCE"]}/{ea.DownloadSource}";
          Engine.Log(LogLevel.Verbose, $"ResolveSource downloadUrl {dlUrl}");
          Engine.SetDownloadSource(ea.PackageOrContainerId,ea.PayloadId, dlUrl,null,null);
        }
        ea.Result = Result.Download;
        }
      }
    }
    

    这当然只是一个非常 hacky 的示例,但您可以在该事件期间使用 Engine.SetDownloadSource 设置正确的 downloadSource。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多