From b8024608744dc59f1dfd61c402938bcb6b4f7699 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 30 Nov 2021 12:35:07 -0800 Subject: Always populate bind variables for file version and language Always populating the values (using "" for null) makes it easier to diagnose when you finally get the bind variable syntax correct. Previously, incorrect syntax and not having a value both resulted in errors. --- .../Bind/UpdateFileFacadesCommand.cs | 21 ++++--------- .../BindVariablesFixture.cs | 35 ++++++++++++++++++++++ .../BindVariables/PackageWithBindVariables.wxs | 20 +++++++++++++ 3 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/BindVariables/PackageWithBindVariables.wxs diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs index 0f77abfc..8043ffa8 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs @@ -195,22 +195,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind { facade.Language = language; } + } - // Populate the binder variables for this file information if requested. - if (null != this.VariableCache) - { - if (!String.IsNullOrEmpty(facade.Version)) - { - var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", facade.Id); - this.VariableCache[key] = facade.Version; - } - - if (!String.IsNullOrEmpty(facade.Language)) - { - var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", facade.Id); - this.VariableCache[key] = facade.Language; - } - } + // Populate the binder variables for this file information if requested. + if (null != this.VariableCache) + { + this.VariableCache[$"fileversion.{facade.Id}"] = facade.Version ?? String.Empty; + this.VariableCache[$"filelanguage.{facade.Id}"] = facade.Language ?? String.Empty; } // If this is a CLR assembly, load the assembly and get the assembly name information diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BindVariablesFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BindVariablesFixture.cs index 39e6b4aa..820f1707 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BindVariablesFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BindVariablesFixture.cs @@ -4,6 +4,7 @@ namespace WixToolsetTest.CoreIntegration { using System; using System.IO; + using System.Linq; using WixBuildTools.TestSupport; using WixToolset.Core.TestPackage; using Xunit; @@ -38,6 +39,40 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void CanBuildPackageWithBindVariables() + { + var folder = TestData.Get(@"TestData", "BindVariables"); + var dotDataFolder = TestData.Get(@"TestData", ".Data"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var msiPath = Path.Combine(intermediateFolder, @"test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "PackageWithBindVariables.wxs"), + "-intermediateFolder", intermediateFolder, + "-bindpath", folder, + "-bindpath", dotDataFolder, + "-o", msiPath, + }); + + result.AssertSuccess(); + + var queryResults = Query.QueryDatabase(msiPath, new[] { "Property" }).ToDictionary(s => s.Split('\t')[0]); + Assert.Equal("Property:ProductVersion\t3.14.1703.0", queryResults["Property:ProductVersion"]); + Assert.Equal("Property:TestPackageManufacturer\tExample Corporation", queryResults["Property:TestPackageManufacturer"]); + Assert.Equal("Property:TestPackageName\tPacakgeWithBindVariables", queryResults["Property:TestPackageName"]); + Assert.Equal("Property:TestPackageVersion\t3.14.1703.0", queryResults["Property:TestPackageVersion"]); + Assert.Equal("Property:TestTextVersion\tv", queryResults["Property:TestTextVersion"]); + Assert.False(queryResults.ContainsKey("Property:TestTextLanguage")); + } + } + [Fact] public void CanBuildWithDefaultValue() { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BindVariables/PackageWithBindVariables.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BindVariables/PackageWithBindVariables.wxs new file mode 100644 index 00000000..377f7e11 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BindVariables/PackageWithBindVariables.wxs @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-55-g6feb