Skip to content

Commit

Permalink
Downgrade bad ProductVersion error to warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnson authored and robmen committed Jun 3, 2023
1 parent 856658a commit 29cec14
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 27 deletions.
6 changes: 0 additions & 6 deletions src/api/wix/WixToolset.Data/ErrorMessages.cs
Expand Up @@ -1306,11 +1306,6 @@ public static Message InvalidPreprocessorVariable(SourceLineNumber sourceLineNum
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);
}

public static Message InvalidProductVersion(SourceLineNumber sourceLineNumbers, string version)
{
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);
}

public static Message InvalidRemoveComponent(SourceLineNumber sourceLineNumbers, string component, string feature, string transformPath)
{
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);
Expand Down Expand Up @@ -2520,7 +2515,6 @@ public enum Ids
InvalidWixTransform = 239,
UnexpectedFileExtension = 240,
UnexpectedTableInPatch = 241,
InvalidProductVersion = 242,
InvalidKeypathChange = 243,
MissingValidatorExtension = 244,
InvalidValidatorMessageType = 245,
Expand Down
11 changes: 11 additions & 0 deletions src/api/wix/WixToolset.Data/WarningMessages.cs
Expand Up @@ -678,6 +678,17 @@ public static Message InvalidMsiProductVersion(SourceLineNumber sourceLineNumber
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);
}

public static Message InvalidMsiProductVersion(SourceLineNumber sourceLineNumbers, string version)
{
return Message(sourceLineNumbers, Ids.InvalidMsiProductVersion,
"Invalid MSI package version: '{0}'. " +
"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. " +
"The revision value is ignored but version labels and metadata are not allowed. " +
"Violating the MSI rules sometimes works as expected but the behavior is unpredictable and undefined. "+
"Future versions of WiX might treat invalid package versions as an error.",
version);
}

public static Message CollidingModularizationTypes(string tableName, string columnName, string foreignTableName, int foreignColumnNumber, string modularizationType, string foreignModularizationType)
{
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);
Expand Down
Expand Up @@ -533,7 +533,7 @@ private void ProcessProductVersion(WixPackageSymbol packageSymbol, IntermediateS
}
else if (validate)
{
this.Messaging.Write(ErrorMessages.InvalidProductVersion(packageSymbol.SourceLineNumbers, packageSymbol.Version));
this.Messaging.Write(WarningMessages.InvalidMsiProductVersion(packageSymbol.SourceLineNumbers, packageSymbol.Version));
}
}

Expand Down
Expand Up @@ -1626,7 +1626,7 @@ private bool CheckUpgradeVersion(UpgradeSymbol symbol, string version, out strin
}
else
{
this.Messaging.Write(ErrorMessages.InvalidProductVersion(symbol.SourceLineNumbers, version));
this.Messaging.Write(WarningMessages.InvalidMsiProductVersion(symbol.SourceLineNumbers, version));
}

changedVersion = null;
Expand Down
2 changes: 1 addition & 1 deletion src/wix/WixToolset.Core/Compiler_Patch.cs
Expand Up @@ -374,7 +374,7 @@ private void ParsePatchFamilyElement(XElement node, ComplexReferenceParentType p
}
else if (!CompilerCore.IsValidProductVersion(version))
{
this.Core.Write(ErrorMessages.InvalidProductVersion(sourceLineNumbers, version));
this.Core.Write(WarningMessages.InvalidMsiProductVersion(sourceLineNumbers, version));
}

// find unexpected child elements
Expand Down
@@ -0,0 +1,31 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Version="!(wix.Version)"
Name="MsiPackage"
Manufacturer="Example Corporation"
UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"
Scope="perUser">
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />
<MediaTemplate EmbedCab="true" />

<Feature Id="ProductFeature" Title="Feature title">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Package>

<Fragment>
<StandardDirectory Id="DesktopFolder">
<Directory Id="INSTALLFOLDER" Name="MsiPackage !(wix.Version) and !(bind.property.ProductVersion)" />
</StandardDirectory>
</Fragment>

<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component>
<File Source="test.txt" />
</Component>
<Component Id="Shared.dll" Shared="yes">
<File Name="Shared.dll" Source="test.txt" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
7 changes: 2 additions & 5 deletions src/wix/test/WixToolsetTest.CoreIntegration/UpgradeFixture.cs
Expand Up @@ -36,11 +36,8 @@ public void FailsOnInvalidVersion()
var errorMessages = result.Messages.Where(m => m.Level == MessageLevel.Error)
.Select(m => m.ToString())
.ToArray();
WixAssert.CompareLineByLine(new[]
{
"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.",
}, errorMessages);
Assert.Equal(242, result.ExitCode);
Assert.StartsWith("Invalid MSI package version: '1.256.0'.", errorMessages.Single());
Assert.Equal(1148, result.ExitCode);
}
}

Expand Down
51 changes: 38 additions & 13 deletions src/wix/test/WixToolsetTest.CoreIntegration/VersionFixture.cs
Expand Up @@ -99,11 +99,8 @@ public void CannotBuildMsiWithExtendedVersion()
var errorMessages = result.Messages.Where(m => m.Level == MessageLevel.Error)
.Select(m => m.ToString())
.ToArray();
WixAssert.CompareLineByLine(new[]
{
"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.",
}, errorMessages);
Assert.Equal(242, result.ExitCode);
Assert.StartsWith("Invalid MSI package version: 'v4.3.2-preview.1'.", errorMessages.Single());
Assert.Equal(1148, result.ExitCode);
}
}

Expand All @@ -118,7 +115,7 @@ public void CannotBuildMsiWithInvalidMajorVersion()
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, @"bin\test1.msi");

var result = WixRunner.Execute(new[]
var result = WixRunner.Execute(warningsAsErrors: false, new[]
{
"build",
Path.Combine(folder, "Version", "PackageWithReplaceableVersion.wxs"),
Expand All @@ -128,14 +125,42 @@ public void CannotBuildMsiWithInvalidMajorVersion()
"-o", msiPath
});

var errorMessages = result.Messages.Where(m => m.Level == MessageLevel.Error)
.Select(m => m.ToString())
.ToArray();
WixAssert.CompareLineByLine(new[]
result.AssertSuccess();

var warningMessages = result.Messages.Where(m => m.Level == MessageLevel.Warning).Select(m => m.ToString()).ToArray();
Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[0]);
Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[1]);
Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[2]);
}
}

[Fact]
public void CannotBuildMsiWithInvalidBindVariableVersion()
{
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(warningsAsErrors: false, new[]
{
"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.",
}, errorMessages);
Assert.Equal(242, result.ExitCode);
"build",
Path.Combine(folder, "Version", "PackageWithUndefinedBindVariableVersion.wxs"),
"-bindpath", Path.Combine(folder, "SingleFile", "data"),
"-intermediateFolder", intermediateFolder,
"-bindvariable", "Version=257.0.0",
"-o", msiPath
});

result.AssertSuccess();

var warningMessages = result.Messages.Where(m => m.Level == MessageLevel.Warning).Select(m => m.ToString()).ToArray();
Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[0]);
Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[1]);
Assert.StartsWith("Invalid MSI package version: '257.0.0'.", warningMessages[2]);
}
}

Expand Down

0 comments on commit 29cec14

Please sign in to comment.