@joebigelow / wix-1 / commits / b8024608

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.

Rob Mensching committed Nov 30, 2021 at 12:35 UTC b8024608744dc59f1dfd61c402938bcb6b4f7699
3 files changed +61 -15
src/wix/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
+6 -15
@@ -195,22 +195,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind
195 {
196 facade.Language = language;
197 }
198 + }
199
199 - // Populate the binder variables for this file information if requested.
200 - if (null != this.VariableCache)
201 - {
202 - if (!String.IsNullOrEmpty(facade.Version))
203 - {
204 - var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", facade.Id);
205 - this.VariableCache[key] = facade.Version;
206 - }
207 -
208 - if (!String.IsNullOrEmpty(facade.Language))
209 - {
210 - var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", facade.Id);
211 - this.VariableCache[key] = facade.Language;
212 - }
213 - }
200 + // Populate the binder variables for this file information if requested.
201 + if (null != this.VariableCache)
202 + {
203 + this.VariableCache[$"fileversion.{facade.Id}"] = facade.Version ?? String.Empty;
204 + this.VariableCache[$"filelanguage.{facade.Id}"] = facade.Language ?? String.Empty;
205 }
206
207 // If this is a CLR assembly, load the assembly and get the assembly name information
src/wix/test/WixToolsetTest.CoreIntegration/BindVariablesFixture.cs
+35
@@ -4,6 +4,7 @@ namespace WixToolsetTest.CoreIntegration
4 {
5 using System;
6 using System.IO;
7 + using System.Linq;
8 using WixBuildTools.TestSupport;
9 using WixToolset.Core.TestPackage;
10 using Xunit;
@@ -38,6 +39,40 @@ namespace WixToolsetTest.CoreIntegration
39 }
40 }
41
42 + [Fact]
43 + public void CanBuildPackageWithBindVariables()
44 + {
45 + var folder = TestData.Get(@"TestData", "BindVariables");
46 + var dotDataFolder = TestData.Get(@"TestData", ".Data");
47 +
48 + using (var fs = new DisposableFileSystem())
49 + {
50 + var baseFolder = fs.GetFolder();
51 + var intermediateFolder = Path.Combine(baseFolder, "obj");
52 + var msiPath = Path.Combine(intermediateFolder, @"test.msi");
53 +
54 + var result = WixRunner.Execute(new[]
55 + {
56 + "build",
57 + Path.Combine(folder, "PackageWithBindVariables.wxs"),
58 + "-intermediateFolder", intermediateFolder,
59 + "-bindpath", folder,
60 + "-bindpath", dotDataFolder,
61 + "-o", msiPath,
62 + });
63 +
64 + result.AssertSuccess();
65 +
66 + var queryResults = Query.QueryDatabase(msiPath, new[] { "Property" }).ToDictionary(s => s.Split('\t')[0]);
67 + Assert.Equal("Property:ProductVersion\t3.14.1703.0", queryResults["Property:ProductVersion"]);
68 + Assert.Equal("Property:TestPackageManufacturer\tExample Corporation", queryResults["Property:TestPackageManufacturer"]);
69 + Assert.Equal("Property:TestPackageName\tPacakgeWithBindVariables", queryResults["Property:TestPackageName"]);
70 + Assert.Equal("Property:TestPackageVersion\t3.14.1703.0", queryResults["Property:TestPackageVersion"]);
71 + Assert.Equal("Property:TestTextVersion\tv", queryResults["Property:TestTextVersion"]);
72 + Assert.False(queryResults.ContainsKey("Property:TestTextLanguage"));
73 + }
74 + }
75 +
76 [Fact]
77 public void CanBuildWithDefaultValue()
78 {
src/wix/test/WixToolsetTest.CoreIntegration/TestData/BindVariables/PackageWithBindVariables.wxs new
+20
@@ -0,0 +1,20 @@
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2 + <Package Name="PacakgeWithBindVariables" Version="!(bind.fileversion.TestBinaryFile)" Manufacturer="Example Corporation" UpgradeCode="00000000-0000-0000-0000-000000000000">
3 +
4 + <Property Id="TestPackageManufacturer" Value="!(bind.Property.Manufacturer)" />
5 + <Property Id="TestPackageName" Value="!(bind.Property.ProductName)" />
6 + <Property Id="TestPackageVersion" Value="!(bind.Property.ProductVersion)" />
7 +
8 + <Property Id="TestTextVersion" Value="v!(bind.fileversion.TestTextFile)" />
9 + <Property Id="TestTextLangauge" Value="!(bind.filelanguage.TestTextFile)" />
10 +
11 + <Feature Id="ProductFeature">
12 + <Component Directory="ProgramFiles6432Folder" Subdirectory="test">
13 + <File Id="TestBinaryFile" Source="burn.exe" />
14 + </Component>
15 + <Component Directory="ProgramFiles6432Folder" Subdirectory="test">
16 + <File Id="TestTextFile" Source="data\test.txt" />
17 + </Component>
18 + </Feature>
19 + </Package>
20 +</Wix>