@joebigelow / wix-1 / commits / ed0a765c

Downgrade bad ProductVersion error to warning.

Fixes https://github.com/wixtoolset/issues/issues/7522.

Bob Arnson committed May 31, 2023 at 16:04 UTC ed0a765c3294f89d26af16a215339e8db3142749
8 files changed +85 -27
src/api/wix/WixToolset.Data/ErrorMessages.cs
-6
@@ -1306,11 +1306,6 @@ namespace WixToolset.Data
1306 return Message(sourceLineNumbers, Ids.InvalidPreprocessorVariable, "Ill-formed preprocessor variable '$({0})'. Variables must have a prefix (like 'var.', 'env.', or 'sys.') and a name at least 1 character long. If the literal string '$({0})' is desired, use '$$({0})'.", variable);
1307 }
1308
1309 - public static Message InvalidProductVersion(SourceLineNumber sourceLineNumbers, string version)
1310 - {
1311 - return Message(sourceLineNumbers, Ids.InvalidProductVersion, "Invalid product version '{0}'. MSI product versions must have a major version less than 256, a minor version less than 256, and a build version less than 65536. The revision value is ignored but version labels and metadata are not allowed.", version);
1312 - }
1313 -
1309 public static Message InvalidRemoveComponent(SourceLineNumber sourceLineNumbers, string component, string feature, string transformPath)
1310 {
1311 return Message(sourceLineNumbers, Ids.InvalidRemoveComponent, "Removing component '{0}' from feature '{1}' is not supported. Either the component was removed or the guid changed in the transform '{2}'. Add the component back, undo the change to the component guid, or remove the entire feature.", component, feature, transformPath);
@@ -2520,7 +2515,6 @@ namespace WixToolset.Data
2515 InvalidWixTransform = 239,
2516 UnexpectedFileExtension = 240,
2517 UnexpectedTableInPatch = 241,
2523 - InvalidProductVersion = 242,
2518 InvalidKeypathChange = 243,
2519 MissingValidatorExtension = 244,
2520 InvalidValidatorMessageType = 245,
src/api/wix/WixToolset.Data/WarningMessages.cs
+11
@@ -678,6 +678,17 @@ namespace WixToolset.Data
678 return Message(sourceLineNumbers, Ids.InvalidMsiProductVersion, "Invalid product version '{0}' in MSI package '{1}'. Product version should have a major version less than 256, a minor version less than 256, and a build version less than 65536. The bundle may incorrectly detect upgrades of this package.", version, package);
679 }
680
681 + public static Message InvalidMsiProductVersion(SourceLineNumber sourceLineNumbers, string version)
682 + {
683 + return Message(sourceLineNumbers, Ids.InvalidMsiProductVersion,
684 + "Invalid MSI package version: '{0}'. " +
685 + "The Windows Installer SDK says that MSI product versions must have a major version less than 256, a minor version less than 256, and a build version less than 65536. " +
686 + "The revision value is ignored but version labels and metadata are not allowed. " +
687 + "Violating the MSI rules sometimes works as expected but the behavior is unpredictable and undefined. "+
688 + "Future versions of WiX might treat invalid package versions as an error.",
689 + version);
690 + }
691 +
692 public static Message CollidingModularizationTypes(string tableName, string columnName, string foreignTableName, int foreignColumnNumber, string modularizationType, string foreignModularizationType)
693 {
694 return Message(null, Ids.CollidingModularizationTypes, "The definition for the '{0}' table's '{1}' column is a foreign key relationship to the '{2}' table's column number {3}. The modularization types of the two column definitions differ: table '{0}' uses type {4} and table '{2}' uses type {5}. Change one of the modularization types so that they match.", tableName, columnName, foreignTableName, foreignColumnNumber, modularizationType, foreignModularizationType);
src/wix/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+1 -1
@@ -533,7 +533,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
533 }
534 else if (validate)
535 {
536 - this.Messaging.Write(ErrorMessages.InvalidProductVersion(packageSymbol.SourceLineNumbers, packageSymbol.Version));
536 + this.Messaging.Write(WarningMessages.InvalidMsiProductVersion(packageSymbol.SourceLineNumbers, packageSymbol.Version));
537 }
538 }
539
src/wix/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
+1 -1
@@ -1626,7 +1626,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1626 }
1627 else
1628 {
1629 - this.Messaging.Write(ErrorMessages.InvalidProductVersion(symbol.SourceLineNumbers, version));
1629 + this.Messaging.Write(WarningMessages.InvalidMsiProductVersion(symbol.SourceLineNumbers, version));
1630 }
1631
1632 changedVersion = null;
src/wix/WixToolset.Core/Compiler_Patch.cs
+1 -1
@@ -374,7 +374,7 @@ namespace WixToolset.Core
374 }
375 else if (!CompilerCore.IsValidProductVersion(version))
376 {
377 - this.Core.Write(ErrorMessages.InvalidProductVersion(sourceLineNumbers, version));
377 + this.Core.Write(WarningMessages.InvalidMsiProductVersion(sourceLineNumbers, version));
378 }
379
380 // find unexpected child elements
src/wix/test/WixToolsetTest.CoreIntegration/TestData/Version/PackageWithUndefinedBindVariableVersion.wxs new
+31
@@ -0,0 +1,31 @@
1 +<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
2 + <Package Version="!(wix.Version)"
3 + Name="MsiPackage"
4 + Manufacturer="Example Corporation"
5 + UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
6 + Scope="perUser">
7 + <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
8 + <MediaTemplate EmbedCab="true" />
9 +
10 + <Feature Id="ProductFeature" Title="Feature title">
11 + <ComponentGroupRef Id="ProductComponents" />
12 + </Feature>
13 + </Package>
14 +
15 + <Fragment>
16 + <StandardDirectory Id="DesktopFolder">
17 + <Directory Id="INSTALLFOLDER" Name="MsiPackage !(wix.Version) and !(bind.property.ProductVersion)" />
18 + </StandardDirectory>
19 + </Fragment>
20 +
21 + <Fragment>
22 + <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
23 + <Component>
24 + <File Source="test.txt" />
25 + </Component>
26 + <Component Id="Shared.dll" Shared="yes">
27 + <File Name="Shared.dll" Source="test.txt" />
28 + </Component>
29 + </ComponentGroup>
30 + </Fragment>
31 +</Wix>
src/wix/test/WixToolsetTest.CoreIntegration/UpgradeFixture.cs
+2 -5
@@ -36,11 +36,8 @@ namespace WixToolsetTest.CoreIntegration
36 var errorMessages = result.Messages.Where(m => m.Level == MessageLevel.Error)
37 .Select(m => m.ToString())
38 .ToArray();
39 - WixAssert.CompareLineByLine(new[]
40 - {
41 - "Invalid product version '1.256.0'. MSI product versions must have a major version less than 256, a minor version less than 256, and a build version less than 65536. The revision value is ignored but version labels and metadata are not allowed.",
42 - }, errorMessages);
43 - Assert.Equal(242, result.ExitCode);
39 + Assert.StartsWith("Invalid MSI package version: '1.256.0'.", errorMessages.Single());
40 + Assert.Equal(1148, result.ExitCode);
41 }
42 }
43
src/wix/test/WixToolsetTest.CoreIntegration/VersionFixture.cs
+38 -13
@@ -99,11 +99,8 @@ namespace WixToolsetTest.CoreIntegration
99 var errorMessages = result.Messages.Where(m => m.Level == MessageLevel.Error)
100 .Select(m => m.ToString())
101 .ToArray();
102 - WixAssert.CompareLineByLine(new[]
103 - {
104 - "Invalid product version 'v4.3.2-preview.1'. MSI product versions must have a major version less than 256, a minor version less than 256, and a build version less than 65536. The revision value is ignored but version labels and metadata are not allowed.",
105 - }, errorMessages);
106 - Assert.Equal(242, result.ExitCode);
102 + Assert.StartsWith("Invalid MSI package version: 'v4.3.2-preview.1'.", errorMessages.Single());
103 + Assert.Equal(1148, result.ExitCode);
104 }
105 }
106
@@ -118,7 +115,7 @@ namespace WixToolsetTest.CoreIntegration
115 var intermediateFolder = Path.Combine(baseFolder, "obj");
116 var msiPath = Path.Combine(baseFolder, @"bin\test1.msi");
117
121 - var result = WixRunner.Execute(new[]
118 + var result = WixRunner.Execute(warningsAsErrors: false, new[]
119 {
120 "build",
121 Path.Combine(folder, "Version", "PackageWithReplaceableVersion.wxs"),
@@ -128,14 +125,42 @@ namespace WixToolsetTest.CoreIntegration
125 "-o", msiPath
126 });
127
131 - var errorMessages = result.Messages.Where(m => m.Level == MessageLevel.Error)
132 - .Select(m => m.ToString())
133 - .ToArray();
134 - WixAssert.CompareLineByLine(new[]
128 + result.AssertSuccess();
129 +
130 + var warningMessages = result.Messages.Where(m => m.Level == MessageLevel.Warning).Select(m => m.ToString()).ToArray();
131 + Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[0]);
132 + Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[1]);
133 + Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[2]);
134 + }
135 + }
136 +
137 + [Fact]
138 + public void CannotBuildMsiWithInvalidBindVariableVersion()
139 + {
140 + var folder = TestData.Get(@"TestData");
141 +
142 + using (var fs = new DisposableFileSystem())
143 + {
144 + var baseFolder = fs.GetFolder();
145 + var intermediateFolder = Path.Combine(baseFolder, "obj");
146 + var msiPath = Path.Combine(baseFolder, @"bin\test1.msi");
147 +
148 + var result = WixRunner.Execute(warningsAsErrors: false, new[]
149 {
136 - "Invalid product version '257.0.0'. MSI product versions must have a major version less than 256, a minor version less than 256, and a build version less than 65536. The revision value is ignored but version labels and metadata are not allowed.",
137 - }, errorMessages);
138 - Assert.Equal(242, result.ExitCode);
150 + "build",
151 + Path.Combine(folder, "Version", "PackageWithUndefinedBindVariableVersion.wxs"),
152 + "-bindpath", Path.Combine(folder, "SingleFile", "data"),
153 + "-intermediateFolder", intermediateFolder,
154 + "-bindvariable", "Version=257.0.0",
155 + "-o", msiPath
156 + });
157 +
158 + result.AssertSuccess();
159 +
160 + var warningMessages = result.Messages.Where(m => m.Level == MessageLevel.Warning).Select(m => m.ToString()).ToArray();
161 + Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[0]);
162 + Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[1]);
163 + Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[2]);
164 }
165 }
166