Warn on preprocessor variable redefinition only when the values are different.
Fixes wixtoolset/issues#5853
Bob Arnson committed
Sep 3, 2018 at 18:19 UTC
a2614e6e11108abba52b9eca8f460d9ab57513f5
7 files changed
+99
-1
src/WixToolset.Core/ExtensibilityServices/PreprocessHelper.cs
+1
-1
@@ -45,7 +45,7 @@ namespace WixToolset.Core.ExtensibilityServices
45
}
46
else
47
{
48
- if (showWarning)
48
+ if (showWarning && value != currentValue)
49
{
50
this.Messaging.Write(WarningMessages.VariableDeclarationCollision(context.CurrentSourceLineNumber, name, value, currentValue));
51
}
src/test/WixToolsetTest.CoreIntegration/PreprocessorFixture.cs
new
+44
@@ -0,0 +1,44 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolsetTest.CoreIntegration
4
+{
5
+ using System.IO;
6
+ using System.Linq;
7
+ using WixBuildTools.TestSupport;
8
+ using WixToolset.Core.TestPackage;
9
+ using WixToolset.Data;
10
+ using WixToolset.Data.Tuples;
11
+ using WixToolset.Data.WindowsInstaller;
12
+ using Xunit;
13
+
14
+ public class PreprocessorFixture
15
+ {
16
+ [Fact]
17
+ public void VariableRedefinitionIsAWarning()
18
+ {
19
+ var folder = TestData.Get(@"TestData\Variables");
20
+
21
+ using (var fs = new DisposableFileSystem())
22
+ {
23
+ var baseFolder = fs.GetFolder();
24
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
25
+
26
+ var result = WixRunner.Execute(new[]
27
+ {
28
+ "build",
29
+ Path.Combine(folder, "Package.wxs"),
30
+ Path.Combine(folder, "PackageComponents.wxs"),
31
+ "-loc", Path.Combine(folder, "Package.en-us.wxl"),
32
+ "-bindpath", Path.Combine(folder, "data"),
33
+ "-intermediateFolder", intermediateFolder,
34
+ "-o", Path.Combine(baseFolder, @"bin\test.msi")
35
+ }, out var messages);
36
+ Assert.Equal(0, result);
37
+
38
+ var warnings = messages.Where(message => message.Id == 1118);
39
+ Assert.Single(warnings);
40
+ }
41
+ }
42
+ }
43
+}
44
+
src/test/WixToolsetTest.CoreIntegration/TestData/Variables/Package.en-us.wxl
new
+11
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<!--
4
+This file contains the declaration of all the localizable strings.
5
+-->
6
+<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">
7
+
8
+ <String Id="DowngradeError">A newer version of [ProductName] is already installed.</String>
9
+ <String Id="FeatureTitle">MsiPackage</String>
10
+
11
+</WixLocalization>
src/test/WixToolsetTest.CoreIntegration/TestData/Variables/Package.wxs
new
+28
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<?define Foo = "Foo" ?>
4
+<?define Foo = "Foo" ?>
5
+
6
+<?define Bar = "Bar" ?>
7
+<?define Bar = "Baz" ?>
8
+
9
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
10
+ <Product Id="*" Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
11
+ <Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" />
12
+
13
+ <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
14
+ <MediaTemplate />
15
+
16
+ <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
17
+ <ComponentGroupRef Id="ProductComponents" />
18
+ </Feature>
19
+ </Product>
20
+
21
+ <Fragment>
22
+ <Directory Id="TARGETDIR" Name="SourceDir">
23
+ <Directory Id="ProgramFilesFolder">
24
+ <Directory Id="INSTALLFOLDER" Name="MsiPackage" />
25
+ </Directory>
26
+ </Directory>
27
+ </Fragment>
28
+</Wix>
src/test/WixToolsetTest.CoreIntegration/TestData/Variables/PackageComponents.wxs
new
+10
@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3
+ <Fragment>
4
+ <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
5
+ <Component>
6
+ <File Source="test.txt" />
7
+ </Component>
8
+ </ComponentGroup>
9
+ </Fragment>
10
+</Wix>
src/test/WixToolsetTest.CoreIntegration/TestData/Variables/data/test.txt
new
+1
@@ -0,0 +1 @@
1
+This is test.txt.
\ No newline at end of file
src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj
+4
@@ -49,6 +49,10 @@
49
<Content Include="TestData\Assembly\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" />
50
<Content Include="TestData\Assembly\Package.wxs" CopyToOutputDirectory="PreserveNewest" />
51
<Content Include="TestData\Assembly\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" />
52
+ <Content Include="TestData\Variables\data\test.txt" CopyToOutputDirectory="PreserveNewest" />
53
+ <Content Include="TestData\Variables\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" />
54
+ <Content Include="TestData\Variables\Package.wxs" CopyToOutputDirectory="PreserveNewest" />
55
+ <Content Include="TestData\Variables\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" />
56
</ItemGroup>
57
58
<ItemGroup>