Skip to content

Use Microsoft.IO.Redist in XMake.cs #10705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/Build/Logging/ProfilerLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
19 changes: 0 additions & 19 deletions src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,25 +1531,6 @@ public void ProcessInvalidTargetSwitch()
#endif
}

/// <summary>
/// Verifies that when the /profileevaluation switch is used with invalid filenames an error is shown.
/// </summary>
[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<ILogger>(), out enableProfiler),
typeof(CommandLineSwitchException));
}

public static IEnumerable<object[]> 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" };
}

/// <summary>
/// Verifies that help messages are correctly formed with the right width and leading spaces.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading