From 71d7380fc9c65c726b1f0d710e2d999b29d87fa8 Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Wed, 25 Sep 2024 14:13:40 -0500 Subject: [PATCH 1/4] Use Microsoft.IO.Redist in XMake.cs This will fix #10540--it looks like M.IO.Redist has the same fix that .NET 9 has that avoids the failed root enumeration. As a bonus it's generally higher performance/less allocatey (but I don't know that that has a specific positive impact in this file). --- src/MSBuild/XMake.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 8411c5408ba..f47e7c3d669 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -43,6 +43,17 @@ using SimpleErrorLogger = Microsoft.Build.Logging.SimpleErrorLogger.SimpleErrorLogger; using TerminalLogger = Microsoft.Build.Logging.TerminalLogger.TerminalLogger; +#if NETFRAMEWORK +// Use I/O operations from Microsoft.IO.Redist which is generally higher perf +// and also works around https://github.com/dotnet/msbuild/issues/10540. +// Unnecessary on .NET 6+ because the perf improvements are in-box there. +using Microsoft.IO; +using Directory = Microsoft.IO.Directory; +using File = Microsoft.IO.File; +using FileInfo = Microsoft.IO.FileInfo; +using Path = Microsoft.IO.Path; +#endif + #nullable disable namespace Microsoft.Build.CommandLine From aa2696bb608f1683f6b2fec43425cbd4b67223bd Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Mon, 7 Oct 2024 16:27:56 -0500 Subject: [PATCH 2/4] Unify ErrorWritingProfilerReport This was repeated but can be simplified. --- src/Build/Logging/ProfilerLogger.cs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Build/Logging/ProfilerLogger.cs b/src/Build/Logging/ProfilerLogger.cs index 77c521d5452..c33a0c15ada 100644 --- a/src/Build/Logging/ProfilerLogger.cs +++ b/src/Build/Logging/ProfilerLogger.cs @@ -297,19 +297,11 @@ private void GenerateProfilerReport() Console.WriteLine(ResourceUtilities.GetResourceString("WritingProfilerReportDone")); } - catch (DirectoryNotFoundException ex) - { - Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorWritingProfilerReport", ex.Message)); - } - catch (IOException ex) - { - Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorWritingProfilerReport", ex.Message)); - } - catch (UnauthorizedAccessException ex) - { - Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorWritingProfilerReport", ex.Message)); - } - catch (SecurityException ex) + catch (Exception ex) when (ex is + DirectoryNotFoundException or + IOException or + UnauthorizedAccessException or + SecurityException) { Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorWritingProfilerReport", ex.Message)); } From f55faa3f14c6c222d285fb5eb2dc9e48ea63ca06 Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Mon, 7 Oct 2024 16:29:14 -0500 Subject: [PATCH 3/4] Extend ErrorWritingProfilerReport to ArgumentException This was thrown from GetExtension with an invalid path on .NET Framework. --- src/Build/Logging/ProfilerLogger.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Build/Logging/ProfilerLogger.cs b/src/Build/Logging/ProfilerLogger.cs index c33a0c15ada..b80dcf8cf0e 100644 --- a/src/Build/Logging/ProfilerLogger.cs +++ b/src/Build/Logging/ProfilerLogger.cs @@ -301,7 +301,8 @@ private void GenerateProfilerReport() DirectoryNotFoundException or IOException or UnauthorizedAccessException or - SecurityException) + SecurityException or + ArgumentException) { Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorWritingProfilerReport", ex.Message)); } From 4fe03ac184267b84b4bc75888ea8f64629f8b2cb Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Mon, 7 Oct 2024 16:30:44 -0500 Subject: [PATCH 4/4] Remove ProcessProfileEvaluationInvalidFilename This tested behavior of System.IO that only appled on .NET Framework and was removed by #10705. Since evaluation profiling is rarely used, I prefer to just drop the test. --- .../CommandLineSwitches_Tests.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs b/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs index 6ffae8dfb52..47e9361022d 100644 --- a/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs +++ b/src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs @@ -1531,25 +1531,6 @@ public void ProcessInvalidTargetSwitch() #endif } - /// - /// Verifies that when the /profileevaluation switch is used with invalid filenames an error is shown. - /// - [MemberData(nameof(GetInvalidFilenames))] - [WindowsFullFrameworkOnlyTheory(additionalMessage: ".NET Core 2.1+ no longer validates paths: https://github.com/dotnet/corefx/issues/27779#issuecomment-371253486.")] - public void ProcessProfileEvaluationInvalidFilename(string filename) - { - bool enableProfiler = false; - Should.Throw( - () => MSBuildApp.ProcessProfileEvaluationSwitch(new[] { filename }, new List(), out enableProfiler), - typeof(CommandLineSwitchException)); - } - - public static IEnumerable GetInvalidFilenames() - { - yield return new object[] { $"a_file_with${Path.GetInvalidFileNameChars().First()}invalid_chars" }; - yield return new object[] { $"C:\\a_path\\with{Path.GetInvalidPathChars().First()}invalid\\chars" }; - } - /// /// Verifies that help messages are correctly formed with the right width and leading spaces. ///