How to use property values within downloadurl in wix

102 Views Asked by At

I need to create a download URL in wix burn based on the user inputs to download a MSI package. I am setting the properties as below and properties set into those variable without a problem when I give them as inputs while creating the .exe package.

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

But the problem is when I use these properties inside the downloadUrl attribute of the MsiPackage element actual values of the properties will not be taken. Burn just recognize them as [PROTOCOL] and [SOURCE]. Following is my MsiPackage element.

<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)"/>

Because of this file is not downloading. So can anyone please tell me how to use the property values inside the MsiPackage element's downloadUrl attribute.

1

There are 1 best solutions below

0
Klemens Altmanninger On

The problem you face is, that those properties are not expanded at runtime (or if they where, when exactly should they be?

a little bit hacky example:

<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)"/>

so just use the DownloadUrl for the latter relative path, and use the OnResolveSource event to set the correct downloadUrl towards the engine:

private void OnResolveSource(object sender, ResolveSourceEventArgs ea)
{
  if( ea.PackageOrContainerId.Equals("SSCE")
  {
    if (!File.Exists(ea.LocalSource) )
    {
    if (!string.IsNullOrEmpty(ea.DownloadSource))
    {
      // 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;
    }
  }
}

This is of course just a very hacky example but you can set the correct downloadSource with Engine.SetDownloadSource during that event.