Skip to content

OutPut the PathTooLong when when longpath is disabled #11731

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/Build/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ internal static void Evaluate(
{
evaluator.Evaluate();
}
catch (PathTooLongException ex)
{
evaluator._evaluationLoggingContext.LogErrorFromText(null, null, null, new BuildEventFileInfo(root.ProjectFileLocation.File),
ex.Message);
}
finally
{
IEnumerable globalProperties = null;
Expand Down
7 changes: 7 additions & 0 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,13 @@ public static ExitType Execute(

exitType = ExitType.Unexpected;
}
catch (PathTooLongException e)
{
Console.WriteLine(
Copy link
Preview

Copilot AI Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using Console.Error.WriteLine instead of Console.WriteLine to ensure error messages are routed properly to the error stream.

Suggested change
Console.WriteLine(
Console.Error.WriteLine(

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

$"{e.Message}{(e.InnerException != null ? $" {e.InnerException.Message}" : string.Empty)}");

exitType = ExitType.Unexpected;
}
// handle fatal errors
catch (Exception e)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Shared/FileSystem/WindowsFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public override IEnumerable<string> EnumerateFileSystemEntries(string path, stri

public override bool DirectoryExists(string path)
{
if (!string.IsNullOrEmpty(path) && FileUtilities.IsPathTooLong(path))
{
// If the path is too long, we can't check if it exists on windows
string message = ResourceUtilities.FormatString(AssemblyResources.GetString("Shared.PathTooLong"), path, NativeMethodsShared.MaxPath);
throw new PathTooLongException(message);
}
return NativeMethodsShared.DirectoryExistsWindows(path);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Shared/FileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ internal static string AttemptToShortenPath(string path)
return FixFilePath(path);
}

private static bool IsPathTooLong(string path)
public static bool IsPathTooLong(string path)
{
// >= not > because MAX_PATH assumes a trailing null
return path.Length >= NativeMethodsShared.MaxPath;
Expand Down