From 796fed6b2623ec29b126238d97becfef71badfbc Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sat, 3 May 2025 23:09:31 -0400 Subject: Customize TARGETDIR DirectoryRef warning. Fixes https://github.com/wixtoolset/issues/issues/9012 --- src/wix/WixToolset.Core/Compiler.cs | 4 ++++ src/wix/WixToolset.Core/CompilerWarnings.cs | 5 ++++ .../DirectoryFixture.cs | 28 +++++++++++++++++++++- .../TestData/Directory/RedundantTargetDir.wxs | 11 +++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/Directory/RedundantTargetDir.wxs (limited to 'src') diff --git a/src/wix/WixToolset.Core/Compiler.cs b/src/wix/WixToolset.Core/Compiler.cs index 21604ad5..e184e86c 100644 --- a/src/wix/WixToolset.Core/Compiler.cs +++ b/src/wix/WixToolset.Core/Compiler.cs @@ -3982,6 +3982,10 @@ namespace WixToolset.Core { this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); } + else if (id == "TARGETDIR") + { + this.Core.Write(CompilerWarnings.DirectoryRefStandardDirectoryDeprecated(sourceLineNumbers)); + } else if (WindowsInstallerStandard.IsStandardDirectory(id)) { 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 return Message(sourceLineNumbers, Ids.DirectoryRefStandardDirectoryDeprecated, "Using DirectoryRef to reference the standard directory '{0}' is deprecated. Use the StandardDirectory element instead.", directoryId); } + public static Message DirectoryRefStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers) + { + 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."); + } + public static Message DefiningStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers, string directoryId) { 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 using System; using System.IO; using System.Linq; - using WixInternal.TestSupport; using WixInternal.Core.TestPackage; + using WixInternal.TestSupport; using WixToolset.Data; using WixToolset.Data.WindowsInstaller; using Xunit; @@ -394,5 +394,31 @@ namespace WixToolsetTest.CoreIntegration }, directoryRows.Select(r => r.FieldAsString(0) + ":" + r.FieldAsString(1) + ":" + r.FieldAsString(2)).OrderBy(s => s).ToArray()); } } + + [Fact] + public void GetsWarningForRedundantTargetDir() + { + 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", "test.msi"); + var wixpdbPath = Path.ChangeExtension(msiPath, ".wixpdb"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Directory", "RedundantTargetDir.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", msiPath + }); + + var error = result.Messages.Single(); + Assert.Equal(5436/*CompilerWarnings.Id.DirectoryRefStandardDirectoryDeprecated*/, error.Id); + } + } } } 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 @@ + + + + + + + + + + + -- cgit v1.2.3-55-g6feb