-
Notifications
You must be signed in to change notification settings - Fork 256
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
NuGet client traverses files in Include before package path parameters are defined #12332
Comments
Thank you for filing this issue. |
The behavior and the warning is coming from MsBuild, not NuGet. |
@aortiz-msft Could you please explain how NuGet restore leads to MSBUILD traversing the wildcard include path? I will then open an issue against them instead. |
@puya-ms The way restore finds Coupled with the fact that MSBuild's scripting language doesn't have the concept of nulls, they're treated as empty strings, this means that In short, you should add |
Thank you @zivkan for the workaround. This ordering issue is not clear (and IMO should not matter) to end user. As an end user I shouldn't care about the implementation of restore and that the NuGet variable is defined after the csproj file is evaluated. Is this mentioned anywhere in the documentation? Is this something that should be fixed / improved on msbuild in your opinion? Maybe MSBUILD should define those variables by evaluating the reference to the package before trying to evaluate anything that uses them, or implement another solution to avoid this. |
My gut feeling is that your proposal will cause significant breaking changes to MSBuild, and will cause more problems to existing customers than customers who will benefit from not needing to learn as much about MSBuild as a scripting language. I'm not a fan of MSBuild at all. I consider it technical debt that is makes some improvements to NuGet more difficult. But it's very tightly coupled now, and many customers use MSBuild extensibility to customize their builds in ways that would be impossible to reproduce without breaking changes, and would be very costly to implement similar (but not equivalent) extensibility. If you're curious about learning more about MSBuild, this is a good starting place to learn about the high level process of how MSBuild loads and executes builds: https://learn.microsoft.com/en-us/visualstudio/msbuild/build-process-overview?view=vs-2022. It also explains the order of import evaluation vs property evaluation vs item evaluation vs target execution. When .NET Core 1.0 was being developed, they tried moving away from MSBuild and created Anyway, I don't work on MSBuild, you can discuss it with them if you like at https://github.com/dotnet/msbuild, but my feeling is that your request is not feasible. The unfortunate reality is that to be an advanced .NET developer, you need to learn MSBuild's quirks. |
I ran into this warning due to a change in behavior in MSBuild that must've occurred in the last year or so. I was previously relying on the following behavior to pack another dependency via transclusion: <ItemGroup>
<PackageReference Include="App.Web" Version="$(AppPackageVersion)" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
<PackageBinDirectoryContents Include="$(PkgApp_Web)\**" />
</ItemGroup>
<!-- Copy the files to the output directory -->
<Target Name="CopyPackageDirectoryFiles" AfterTargets="Build">
<Message Importance="High" Text="%24(PkgApp_Web) [$(PkgApp_Web)]" />
<PropertyGroup>
<ActualPackageVersion>$([System.IO.Path]::GetFileName($(PkgApp_Web)))</ActualPackageVersion>
<!--<Version>
$(ActualPackageVersion)+build.$(BuildNumber)
</Version>-->
</PropertyGroup>
<Message Importance="High" Text="%24(ActualPackageVersion) [$(ActualPackageVersion)]" />
<Copy SourceFiles="@(PackageBinDirectoryContents)" DestinationFiles="@(PackageBinDirectoryContents->'$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
</Target> Moving the ItemGroup that defines |
The package path property is only set after a restore has completed (and running a target other than restore). Before restore (or during the restore target), the package path property isn't defined, hence the warning. It works as you expect when you put the item definition inside the target, because the target says |
It used to work differently, though. I suspect the change has something to do with this open bug in MSBuild: dotnet/msbuild#5937 I do not disagree with your assessment that my new approach is semantically correct and the old one was hokey pokey. Overall, I am glad this warning exists. I think one outcome from this discussion that would be a net positive would be to document this MSBuild warning, with more context around how it could occur. In particular, your note here was very helpful:
|
NuGet Product Used
NuGet.exe
Product Version
6.4.0.123
Worked before?
No
Impact
It bothers me. A fix would be nice
Repro Steps & Context
Create a CSPROJ file with a section like this:
Try running
nuget.exe restore
on a solution containing this project:I think correct behavior would be that =NuGet restore command does not try to iterate these files, or if for some reason this is needed, to first define the path variables.
Verbose Logs
No response
The text was updated successfully, but these errors were encountered: