From 4d6476d43973bc4ebee1ff246fb3e5c88b024bc4 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 28 Dec 2024 23:51:28 -0800 Subject: [PATCH] Overridable WixVariables should be treated as virtual Fixes 8528 --- src/wix/WixToolset.Core/Compiler_Package.cs | 5 +++ .../PackageWithOverriddenBindVariable.wxs | 13 +++++++ .../WixVariableFixture.cs | 39 ++++++++++++++++--- 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/PackageWithOverriddenBindVariable.wxs diff --git a/src/wix/WixToolset.Core/Compiler_Package.cs b/src/wix/WixToolset.Core/Compiler_Package.cs index 853c6ed20..479a1ab3e 100644 --- a/src/wix/WixToolset.Core/Compiler_Package.cs +++ b/src/wix/WixToolset.Core/Compiler_Package.cs @@ -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, diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/PackageWithOverriddenBindVariable.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/PackageWithOverriddenBindVariable.wxs new file mode 100644 index 000000000..fdc2a461e --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/PackageWithOverriddenBindVariable.wxs @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/WixVariableFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/WixVariableFixture.cs index 50199b748..b6aea217d 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/WixVariableFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/WixVariableFixture.cs @@ -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); } } @@ -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(); @@ -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(); @@ -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() { @@ -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")); @@ -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; }