aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Arnson <bob@firegiant.com>2025-05-03 23:09:31 -0400
committerBob Arnson <bob@firegiant.com>2025-05-03 23:09:31 -0400
commit14cd8ca245e57d5ba986e111a9cfbb80abbc7ab2 (patch)
tree0c89cc4d5948b04bbda45ab774a3a4037adf2942
parentffbfeb3c0b9cb8084bd366404c0cb06d42e8caaf (diff)
downloadwix-bob/DirectoryRefTargetDir.tar.gz
wix-bob/DirectoryRefTargetDir.tar.bz2
wix-bob/DirectoryRefTargetDir.zip
Customize TARGETDIR DirectoryRef warning.bob/DirectoryRefTargetDir
Fixes https://github.com/wixtoolset/issues/issues/9012
-rw-r--r--src/wix/WixToolset.Core/Compiler.cs4
-rw-r--r--src/wix/WixToolset.Core/CompilerWarnings.cs5
-rw-r--r--src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs28
-rw-r--r--src/wix/test/WixToolsetTest.CoreIntegration/TestData/Directory/RedundantTargetDir.wxs11
4 files changed, 47 insertions, 1 deletions
diff --git a/src/wix/WixToolset.Core/Compiler.cs b/src/wix/WixToolset.Core/Compiler.cs
index 2efca5eb..3519382d 100644
--- a/src/wix/WixToolset.Core/Compiler.cs
+++ b/src/wix/WixToolset.Core/Compiler.cs
@@ -3982,6 +3982,10 @@ namespace WixToolset.Core
3982 { 3982 {
3983 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); 3983 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id"));
3984 } 3984 }
3985 else if (id == "TARGETDIR")
3986 {
3987 this.Core.Write(CompilerWarnings.DirectoryRefStandardDirectoryDeprecated(sourceLineNumbers));
3988 }
3985 else if (WindowsInstallerStandard.IsStandardDirectory(id)) 3989 else if (WindowsInstallerStandard.IsStandardDirectory(id))
3986 { 3990 {
3987 this.Core.Write(CompilerWarnings.DirectoryRefStandardDirectoryDeprecated(sourceLineNumbers, id)); 3991 this.Core.Write(CompilerWarnings.DirectoryRefStandardDirectoryDeprecated(sourceLineNumbers, id));
diff --git a/src/wix/WixToolset.Core/CompilerWarnings.cs b/src/wix/WixToolset.Core/CompilerWarnings.cs
index f4ac6afe..97d20ba6 100644
--- a/src/wix/WixToolset.Core/CompilerWarnings.cs
+++ b/src/wix/WixToolset.Core/CompilerWarnings.cs
@@ -11,6 +11,11 @@ namespace WixToolset.Core
11 return Message(sourceLineNumbers, Ids.DirectoryRefStandardDirectoryDeprecated, "Using DirectoryRef to reference the standard directory '{0}' is deprecated. Use the StandardDirectory element instead.", directoryId); 11 return Message(sourceLineNumbers, Ids.DirectoryRefStandardDirectoryDeprecated, "Using DirectoryRef to reference the standard directory '{0}' is deprecated. Use the StandardDirectory element instead.", directoryId);
12 } 12 }
13 13
14 public static Message DirectoryRefStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers)
15 {
16 return Message(sourceLineNumbers, Ids.DirectoryRefStandardDirectoryDeprecated, "Using DirectoryRef to reference the standard directory 'TARGETDIR' is deprecated. WiX automatically supplies a root 'TARGETDIR' directory, so you can just omit a DirectoryRef to 'TARGETDIR'. You can also use the StandardDirectory element instead.");
17 }
18
14 public static Message DefiningStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers, string directoryId) 19 public static Message DefiningStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers, string directoryId)
15 { 20 {
16 return Message(sourceLineNumbers, Ids.DefiningStandardDirectoryDeprecated, "It is no longer necessary to define the standard directory '{0}'. Use the StandardDirectory element instead.", directoryId); 21 return Message(sourceLineNumbers, Ids.DefiningStandardDirectoryDeprecated, "It is no longer necessary to define the standard directory '{0}'. Use the StandardDirectory element instead.", directoryId);
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs
index 4781a115..c132eb80 100644
--- a/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs
@@ -5,8 +5,8 @@ namespace WixToolsetTest.CoreIntegration
5 using System; 5 using System;
6 using System.IO; 6 using System.IO;
7 using System.Linq; 7 using System.Linq;
8 using WixInternal.TestSupport;
9 using WixInternal.Core.TestPackage; 8 using WixInternal.Core.TestPackage;
9 using WixInternal.TestSupport;
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Data.WindowsInstaller; 11 using WixToolset.Data.WindowsInstaller;
12 using Xunit; 12 using Xunit;
@@ -394,5 +394,31 @@ namespace WixToolsetTest.CoreIntegration
394 }, directoryRows.Select(r => r.FieldAsString(0) + ":" + r.FieldAsString(1) + ":" + r.FieldAsString(2)).OrderBy(s => s).ToArray()); 394 }, directoryRows.Select(r => r.FieldAsString(0) + ":" + r.FieldAsString(1) + ":" + r.FieldAsString(2)).OrderBy(s => s).ToArray());
395 } 395 }
396 } 396 }
397
398 [Fact]
399 public void GetsWarningForRedundantTargetDir()
400 {
401 var folder = TestData.Get(@"TestData");
402
403 using (var fs = new DisposableFileSystem())
404 {
405 var baseFolder = fs.GetFolder();
406 var intermediateFolder = Path.Combine(baseFolder, "obj");
407 var msiPath = Path.Combine(baseFolder, "bin", "test.msi");
408 var wixpdbPath = Path.ChangeExtension(msiPath, ".wixpdb");
409
410 var result = WixRunner.Execute(new[]
411 {
412 "build",
413 Path.Combine(folder, "Directory", "RedundantTargetDir.wxs"),
414 "-bindpath", Path.Combine(folder, "SingleFile", "data"),
415 "-intermediateFolder", intermediateFolder,
416 "-o", msiPath
417 });
418
419 var error = result.Messages.Single();
420 Assert.Equal(5436/*CompilerWarnings.Id.DirectoryRefStandardDirectoryDeprecated*/, error.Id);
421 }
422 }
397 } 423 }
398} 424}
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Directory/RedundantTargetDir.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Directory/RedundantTargetDir.wxs
new file mode 100644
index 00000000..f8a42a1b
--- /dev/null
+++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/Directory/RedundantTargetDir.wxs
@@ -0,0 +1,11 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <ComponentGroup Id="ProductComponents" Directory="BinFolder" />
5 </Fragment>
6 <Fragment>
7 <DirectoryRef Id="TARGETDIR">
8 <Directory Id="BinFolder" Name="Example Corporation\Test Product\bin" />
9 </DirectoryRef>
10 </Fragment>
11</Wix>