-
Notifications
You must be signed in to change notification settings - Fork 255
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
Pack Task includes private package reference incorrectly #6317
Comments
It appears the Restore isn't correctly populating the project.assets.json file with the correct metadata Here's with/without the project.assets.json.txt I am guessing that the issue is that restore can't process targets from nuget's as they aren't available yet. The Pack targets thus cannot read the assets file for package reference data since it's not up-to-date. It has to get the PackageReference items from MSBuild to be correct. |
Note that this can help library authors workaround #4125 by including a targets file that updates the |
project.assets.json looks correct to me
SuppressParent = PrivateAssets I am not clear on what the issue is here, this package is suppose to be changing other PackageReferences and they aren't showing up correctly? |
I ran the restore twice, that's the correct one. The other one matches the binlog. The issue is that a package has a targets file that updates the PackageRef Metadata to set privateassets=all. That is reflected in the build phase, but not in the generated package since the pack task creates the dependency list based off of the assets file instead of the current msbuild item state. |
This is by design so that the packed nupkg matches the same behavior as the project. |
My point is that with msbuild, the project itself can be dynamic. The attributes of package reference can change after restore. |
@onovotny I'm pretty sure that isn't supported. Wouldn't that be the same as allowing package references to be added as a result of restore? |
@davidfowl It's similar, but slightly different. Adding another package means you'd need another restore-pass to download it and process the generated props/targets. This is about updating an existing PackageRef's metadata that controls whether it should be added as dependency or not. Honestly, the only real reason I can think of where this is useful is as a workaround to #4125. If that issue was fixed so that |
Note that if/when a |
I understand the need for participating at a lower level like this, but I think it is a special case when the package is trying to modify how nuget itself works for the project instead of just being consumed by the project. An SDK resolver would fix this, but in that case the user is intentionally referencing a package to modify the inputs to restore. With a normal package reference there is no way to tell if the package is intended to modify how NuGet works, or if it would be incorrect to treat the outputs of the package as inputs to NuGet. Which means we cannot add the feature requested in this issue without breaking things. I suggest using this pattern to modify things before restore:
|
Understood.... I think the real thing is to fix #4125 then as that's "how nuget works," and I was trying to change that to fix that package-side instead of NuGet-side. |
@nkolev92 for #4125, the pack scenario is a bit different. We plan to trim dev dependencies when restoring higher level projects that do not need them. For pack we would need to mark these somehow (basically changing the inputs after getting the output) so that pack also knows that for the consumer of the package they should be ignored. |
I'm not sure I'm following. I don't understand why a development dependency should be marked as the nuget at all? Or if that's the intended use of |
In my utility package, I'm trying to update the
MSBuild.Sdk.Extras
PackageReference
to add thePrivateAssets="all"
metadata in my targets file so that the user doesn't have to remember this.This is an attempt at a workaround until NuGet properly excludes
developerDependency
packages by default.My workaround works for single target packages (
TargetFramework
), but fails for multitargeting (TargetFrameworks
).Looking at the MSBuild metadata items, the
MSBuild.Sdk.Extras
all appear to have thePrivateAssets="all"
meta data attached, so I'm not sure why the pack targets is emitting them as dependencies.To repro:
Checkout https://github.com/onovotny/MSBuildSdkExtras
Get commit
296ad3855a23ac3964774624bdf144bccc9a3968
Go to
/Samples/ClasslibraryFromNuGet
Run
msbuild /t:restore
thenmsbuild /t:pack
. The generated nuspec incorrectly lists theMSBuild.Sdk.Extras
dependency.I've attached a binlog showing that the metadata appears on the expected items.
msbuild.binlog.zip
The text was updated successfully, but these errors were encountered: