diff --git a/src/Build/Logging/ProfilerLogger.cs b/src/Build/Logging/ProfilerLogger.cs index 77c521d5452..b80dcf8cf0e 100644 --- a/src/Build/Logging/ProfilerLogger.cs +++ b/src/Build/Logging/ProfilerLogger.cs @@ -297,19 +297,12 @@ 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 or + ArgumentException) { Console.WriteLine(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorWritingProfilerReport", ex.Message)); } 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. /// diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index c6e0ca436ba..d850697a06f 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