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

Improve docs on pack's CopyToOutput and Flatten #3274

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions docs/reference/msbuild-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ The following table describes the MSBuild properties that can be added to a proj
| `NuspecBasePath` | Base path for the *.nuspec* file. For more information, see [Packing using a .nuspec](#packing-using-a-nuspec-file). |
| `NuspecProperties` | Semicolon separated list of key=value pairs. For more information, see [Packing using a .nuspec](#packing-using-a-nuspec-file). |

### package item inputs

As described in the section on [including content in your package](#including-content-in-a-package), there is certain [item metadata](/visualstudio/msbuild/msbuild-items#item-metadata) that can be added to [MSBuild items](/visualstudio/msbuild/msbuild-items), which pack will use.

| Metadata | Description |
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe the nuspec allows files under contentFiles/ to set whatever item type they want, for example, you could have contentFiles/cs/any/stuff.cs and make it a <Compile item, not <Content.

@nkolev92 do you remember how to specify this? I didn't have much of a search yet, so if you don't know, don't waste time looking for it yourself, I'm just hoping you can save me some time 😁

Copy link
Member

Choose a reason for hiding this comment

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

BuildAction

Copy link
Member

Choose a reason for hiding this comment

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

|:--|:--|
| Pack | The file that this item represents should be included in the package. For items of type `Content` this defaults to the value of the `IncludeContentInPack` property. For all other item types, this defaults to `false`. |
| PackagePath | The path within the package that the file will be located. For items of type `Content`, this defaults to `content\;contentFiles\any\any\`. For all other items types, there is no default value. |
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm too lazy to edit the PR right now, but I think it would be worthwhile mentioning that this metadata allows package authors to put any file in any location in the package, even ones that are not part of any NuGet convention.


The following item metadata only apply to files in the package that follow the correct `contentFiles/{language}/{target_framework}/**/*` naming convention, and the project using the package must be using `PackageReference` (not *packages.config*).
More information can be found in on [including content in your package](#including-content-in-a-package).

| Metadata | Description |
|:--|:--|
| PackageCopyToOutput | The file's `CopyToOutput` item metadata will be set the specified value in the project using the package. |
| PackageFlatten | The file's `Flatten` item metadata will be set to the specified value in the project using the package. |
Comment on lines +130 to +131
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd love to link to some docs where customers can learn more about CopyToOutput and Flatten, but I can't find any Does anyone know where these are documented?

Copy link
Member Author

Choose a reason for hiding this comment

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

Rainer pointed me to CopyToOutputDirectory documented on https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2022

I guess this is what PackageCopyToOutput sets, but since the NuGet name is missing Directory I feel like it's something we need to validate.

I still haven't found docs on Flatten though.

Copy link
Member

@nkolev92 nkolev92 Apr 4, 2024

Choose a reason for hiding this comment

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

I'd add BuildAction here.

In general, the BuildAction defaults to the item type.


## pack scenarios

### Suppressing dependencies
Expand Down