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

Graph restore fails due to unexpanded wildcards #14018

Open
dfederm opened this issue Dec 23, 2024 · 2 comments
Open

Graph restore fails due to unexpanded wildcards #14018

dfederm opened this issue Dec 23, 2024 · 2 comments

Comments

@dfederm
Copy link

dfederm commented Dec 23, 2024

NuGet Product Used

MSBuild.exe

Product Version

various

Worked before?

no

Impact

It's more difficult to complete my work

Repro Steps & Context

Project with something like:

    <ZipContent Include="ItemTemplates\**\*">
      <Archive>ItemTemplates\$([System.IO.Path]::GetDirectoryName('%(RecursiveDir)')).zip</Archive>
      <ArchivePath>%(Filename)%(Extension)</ArchivePath>
    </ZipContent>

results in:

MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form.

Upon inspecting the binlog (after commenting out the metadata):

image

Poking around I found that static graph restore sets MSBuildSkipEagerWildCardEvaluationRegexes to avoid expanding wildcards.

Note: For this specific case a workaround is to use this instead:

<Archive>ItemTemplates\$([System.String]::Copy('%(RecursiveDir)').TrimEnd('\')).zip</Archive>

Since the intent of using Path.GetDirectoryName was simply to remove the trailing slash from %(RecursiveDir)

Verbose Logs

No response

@zivkan zivkan added Functionality:Restore WaitingForCustomer Applied when a NuGet triage person needs more info from the OP Area:RestoreStaticGraph Issues related to the Static Graph restore Triage:NeedsTriageDiscussion and removed Triage:Untriaged WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Dec 24, 2024
@zivkan
Copy link
Member

zivkan commented Dec 24, 2024

I was able to reproduce. It only happens with MSBuild.exe, not with dotnet restore.

@zivkan
Copy link
Member

zivkan commented Dec 24, 2024

If I put the <ItemGroup> in a <Target>, rather than the project evaluation, the warning isn't raised on restore (since MSBuild doesn't need to create the items yet).

@dfederm as far as I can tell item ZipContent isn't "well known", as in something built into MSBuild will read these items. Therefore, I assume you have a custom target somewhere where these items are passed to some task. Are these guesses correct? Is there a good reason that your project is defining this item at evaluation rather than in a target?

When people are back from holidays, we'll discuss in the triage meeting, but I suspect disabling wildcards is part of the design goal of static restore. Static restore was created for huge repos with hundreds of projects, and one of the ways to make restore faster is to not have MSBuild create items that restore doesn't need, like <Compile Include="**/*.cs" />. All that file globbing is measurably slow on large enough repos.

Therefore, maybe we have a docs improvement, otherwise I'm guessing this might end up being a won't fix. But the team will discuss it in January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants