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

Specify that PrivateAssets="all" also affects Publish Fixes #3270 #3291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ Allowable values for these tags are as follows, with multiple values separated b
| analyzers | .NET analyzers |
| native | Contents of the `native` folder |
| none | None of the above are used. |
| all | All of the above (except `none`) |
| all | All of the above (except `none`). Also turns off "Publish" by default. |
Copy link
Member

Choose a reason for hiding this comment

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

Is this documented anywhere on the SDK side?

Personally, I've always thought this was an incorrect decision that we unfortunately can't roll back, but it is still an SDK side decision, not NuGet. So I think the NuGet docs should reference an SDK side explanation.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think it's documented anywhere. I'm not sure where the code that does this is, but I imagine most customers who are looking for something like PrivateAssets="all" will find the NuGet docs, so I think we do need to mention it here.

I don't know where I'd add that in any SDK docs, so although I'm not against having it there somewhere there and having a link to that here, I'd probably have to dig around a bit to find where an appropriate place might be—unless you already have somewhere in mind for that?

Copy link
Member

Choose a reason for hiding this comment

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

I think publish docs should have it.

Copy link
Author

Choose a reason for hiding this comment

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

Are you talking about https://learn.microsoft.com/dotnet/core/deploying/? I don't see anything that connects to how metadata (like PrivateAssets) would affect publishing...since that page was mostly talking about high-level things (what can you pass to the publish command), I feel like this would belong on a different page, but I didn't see anything better.

Copy link
Member

Choose a reason for hiding this comment

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

I think any doc that may be talking about publish actually does.

The PackageReference attribute Publish is a publish first thing, not a PackageReference first thing.
It never flows through the assets file.

PrivateAssets means what my consumers get, it never affects what gets consumed at build time. You can take a compile time or runtime dependency on a package that you've marked with PrivateAssets.
ExcludeAssets/IncludeAssets handle whether you're allowed to take that dependency.

Publish is different from build.

That being said, i think this discussion is related to dotnet/sdk#39400 now.

Copy link
Author

Choose a reason for hiding this comment

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

My understanding from that discussion is that this is still correct and unlikely to change. I couldn't find anywhere on the SDK side that documented any part of this scenario. Are you ok with merging this?


To set `PrivateAssets` to `all` without affecting publishing behavior, set `PrivateAssets` to `all` and `Publish` to `true` as in the first example below:

```xml
<ItemGroup>
<!-- ... -->
<!-- This specifies all assets to be consumed without letting them flow to the parent project, -->
<!-- and it publishes the contents as normal -->
<PackageReference Include="Contoso.PrivateUtilities" Version="3.6.0" PrivateAssets="all" Publish="true" />
<!-- ... -->
<!-- Everything except the content files will be consumed by the project -->
<!-- Everything except content files and analyzers will flow to the parent project-->
Expand Down