Skip to content
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

RestoreTaskEx needs to use a response file when calling NuGet.Build.Tasks.Console.exe #12843

Closed
jaredpar opened this issue Aug 24, 2023 · 6 comments
Labels
Area:RestoreStaticGraph Issues related to the Static Graph restore Functionality:Restore Resolution:Duplicate This issue appears to be a Duplicate of another issue Type:Bug

Comments

@jaredpar
Copy link

jaredpar commented Aug 24, 2023

NuGet Product Used

MSBuild.exe

Product Version

Visual Studio 17.7 but guessing any existing release has this behavior

Worked before?

The bug has seemingly always existed but was recently exposed due to our increase in code size

Impact

I'm unable to use this version

Repro Steps & Context

Repro steps:

  1. Clone https://github.com/dotnet/roslyn
  2. Run Build.cmd -restore -pack

This will error with

...\NuGet.RestoreEx.targets(19,5): error : The filename or extension is too
long [Z:\src\Features\LanguageServer\Microsoft.CodeAnalysis.LanguageServer\Microsoft.CodeAnalysis.LanguageServer.csproj]

The reason is RestoreTaskEx project shells out to NuGet.Build.Tasks.Console.exe. One of the arguments it passes is a mapping of projects in the restore plus, their absolute path and several configuration.

Example:

  <ProjectConfiguration Project="{4B45CA0C-03A0-400F-B454-3D4BCB16AF38}" AbsolutePath="C:\Users\jaredpar\code\roslyn\src\Compilers\CSharp\csc\AnyCpu\csc.csproj" BuildProjectInSolution="True">Debug|AnyCPU</ProjectConfiguration>

I'm unsure what criteria is used here (assume it's just transitive dependencies) but it does scale with the number of included projects. That means once enough projects are included in the restore operation the command argument can exceed the maximum command line length. This will result in the RestoreTaskEx task failing as it exceeds this limit.

Believe that RestoreTaskEx and NuGet.Build.Tasks.Console.exe should be communicating via a response file. This is common practice when shelling out from a build task to a tool that takes command lines whose length scales with the size of the build input.

Verbose Logs

Can provide a binary log if this helps with the diagnosis. Here is the full invocation for Nuget.Build.Tasks.Console.exe

https://gist.github.com/jaredpar/7d73ac0106613d6b0c9a375043d3b9f6

@jaredpar
Copy link
Author

Small update. The restore operation which triggers this error is coming from a nested <MSBuild> invocation. One of our team members discovered we can work around this by disabling static graph on that restore operation

        <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Restore" Properties="RestoreWithR2R=true;RestoreUseStaticGraphEvaluation=false" />

That gives us a temporary work around. Hopefully helps pinpoint the issue a bit for you all :)

jaredpar added a commit to jaredpar/roslyn that referenced this issue Aug 24, 2023
Running `Build.cmd -pack -restore` on most machines is leading to the
following error:

> \NuGet.RestoreEx.targets(19,5): error : The filename or extension is
too long

This seems to be caused by an excessively long command line being passed
to a tool within the NuGetRestoreEx task. Temporarily working around
this by disabling static graph on this restore operation.

NuGet/Home#12843
jaredpar added a commit to jaredpar/roslyn that referenced this issue Aug 24, 2023
Running `Build.cmd -pack -restore` on most machines is leading to the
following error:

> \NuGet.RestoreEx.targets(19,5): error : The filename or extension is
too long

This seems to be caused by an excessively long command line being passed
to a tool within the NuGetRestoreEx task. Temporarily working around
this by disabling static graph on this restore operation.

NuGet/Home#12843
@jeffkl
Copy link
Contributor

jeffkl commented Aug 24, 2023

Duplicate of #11968

@jeffkl jeffkl marked this as a duplicate of #11968 Aug 24, 2023
@jeffkl
Copy link
Contributor

jeffkl commented Aug 24, 2023

I tried fixing this once and it caused a regression so we reverted it since not very many people hit the original issue. NuGet/NuGet.Client#4772

@kartheekp-ms kartheekp-ms added Functionality:Restore Area:RestoreStaticGraph Issues related to the Static Graph restore Resolution:Duplicate This issue appears to be a Duplicate of another issue and removed Triage:Untriaged labels Aug 25, 2023
@kartheekp-ms
Copy link
Contributor

kartheekp-ms commented Aug 25, 2023

Duplicate of # 11968 see above #12843 (comment)

@jaredpar
Copy link
Author

Will move conversation over to #11968. It's a bit discouraging to see that particular issue has been opened for over a year now with no resolution. This is a frustratingly hard problem to diagnose when hit and the build is unusable until you root cause it.

@jeffkl
Copy link
Contributor

jeffkl commented Sep 14, 2023

Will move conversation over to #11968. It's a bit discouraging to see that particular issue has been opened for over a year now with no resolution. This is a frustratingly hard problem to diagnose when hit and the build is unusable until you root cause it.

@jaredpar in NuGet/NuGet.Client#5413 it will now automatically detect if the command-line argument string is too long and serialize global properties over STDIN. I also added better error handling which will log much clearer errors if something happens during argument parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:RestoreStaticGraph Issues related to the Static Graph restore Functionality:Restore Resolution:Duplicate This issue appears to be a Duplicate of another issue Type:Bug
Projects
None yet
Development

No branches or pull requests

3 participants