Skip to content

Commit

Permalink
Overridable WixVariables should be treated as virtual
Browse files Browse the repository at this point in the history
Fixes 8528
  • Loading branch information
robmen committed Dec 29, 2024
1 parent a4fb0e4 commit 4d6476d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/wix/WixToolset.Core/Compiler_Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5033,6 +5033,11 @@ private void ParseWixVariableElement(XElement node)

if (!this.Core.EncounteredError)
{
if (overridable)
{
id = new Identifier(AccessModifier.Virtual, id.Id);
}

this.Core.AddSymbol(new WixVariableSymbol(sourceLineNumbers, id)
{
Value = value,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="1.0.0" Name="MsiPackage" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<PropertyRef Id="Test" />

<WixVariable Id="override TestWixVariable" Value="0"/>
</Package>

<Fragment>
<Property Id="Test" Value="!(wix.TestWixVariable)" />

<WixVariable Id="TestWixVariable" Value="1" Overridable="true"/>
</Fragment>
</Wix>
39 changes: 33 additions & 6 deletions src/wix/test/WixToolsetTest.CoreIntegration/WixVariableFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void CanBuildMsiWithBindVariable()

result.AssertSuccess();

var productVersion = GetProductVersionFromMsi(msiPath);
var productVersion = GetPropertyFromMsi(msiPath, "ProductVersion");
Assert.Equal("4.3.2.1", productVersion);
}
}
Expand All @@ -62,7 +62,7 @@ public void CanBuildMsiWithDefaultedBindVariable()

result.AssertSuccess();

var productVersion = GetProductVersionFromMsi(msiPath);
var productVersion = GetPropertyFromMsi(msiPath, "ProductVersion");
Assert.Equal("1.1.1.1", productVersion);

var directoryTable = Query.QueryDatabase(msiPath, new[] { "Directory" }).OrderBy(s => s).ToArray();
Expand Down Expand Up @@ -98,7 +98,7 @@ public void CanBuildMsiWithPrefixedVersionBindVariable()

result.AssertSuccess();

var productVersion = GetProductVersionFromMsi(msiPath);
var productVersion = GetPropertyFromMsi(msiPath, "ProductVersion");
Assert.Equal("9.8.7.6", productVersion);

var directoryTable = Query.QueryDatabase(msiPath, new[] { "Directory" }).OrderBy(s => s).ToArray();
Expand All @@ -111,6 +111,33 @@ public void CanBuildMsiWithPrefixedVersionBindVariable()
}
}

[Fact]
public void CanBuildMsiWithOverridableBindVariable()
{
var folder = TestData.Get(@"TestData");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, "bin", "test1.msi");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, "WixVariable", "PackageWithOverriddenBindVariable.wxs"),
"-bindpath", Path.Combine(folder, "SingleFile", "data"),
"-intermediateFolder", intermediateFolder,
"-o", msiPath
});

result.AssertSuccess();

var testValue = GetPropertyFromMsi(msiPath, "Test");
Assert.Equal("0", testValue);
}
}

[Fact]
public void CanBuildBundleWithBindVariable()
{
Expand Down Expand Up @@ -150,7 +177,7 @@ public void CanBuildBundleWithBindVariable()

result3.AssertSuccess();

var productVersion = GetProductVersionFromMsi(msiPath);
var productVersion = GetPropertyFromMsi(msiPath, "ProductVersion");
WixAssert.StringEqual("255.255.65535", productVersion);

var extractResult = BundleExtractor.ExtractAllContainers(null, bundlePath, Path.Combine(baseFolder, "ba"), Path.Combine(baseFolder, "attached"), Path.Combine(baseFolder, "extract"));
Expand All @@ -163,10 +190,10 @@ public void CanBuildBundleWithBindVariable()
}
}

private static string GetProductVersionFromMsi(string msiPath)
private static string GetPropertyFromMsi(string msiPath, string propertyId)
{
var propertyTable = Query.QueryDatabase(msiPath, new[] { "Property" }).Select(r => r.Split('\t')).ToDictionary(r => r[0].Substring("Property:".Length), r => r[1]);
Assert.True(propertyTable.TryGetValue("ProductVersion", out var productVersion));
Assert.True(propertyTable.TryGetValue(propertyId, out var productVersion), $"Failed to find requested property: '{propertyId}'");

return productVersion;
}
Expand Down

0 comments on commit 4d6476d

Please sign in to comment.