Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set NuGet contentFiles CopyToOutput to true when using a .NET Standard library .csproj?

I've been looking for any way to set the CopyToOutput attribute to true for content files I'm including in a NuGet package built in VS2017 from a .NET Standard Library project.

When adding the files using the Content node, I can see the files in the package, but when looking at the nuspec that is pulled out when it's cached locally, there is no CopyToOutput, so it's false by default. In this case, when it's referenced in an ASP.NET Core site, nothing is copied into the application. If I manually update that cached version to include the attribute and set it to true and restore, everything gets copied.

Unfortunately, I looked into the Nuget.Build.Tasks.Pack.dll and it looks like there's no way to pass that value through an MSBuild property.

Did anybody run into this issue and has a workaround?

like image 524
Chris Biggs Avatar asked May 19 '17 15:05

Chris Biggs


People also ask

Do I need a Nuspec file?

nuspec file is not required to create packages for SDK-style projects (typically . NET Core and . NET Standard projects that use the SDK attribute).

How do I get files from a NuGet package?

on the toolbar of the Assembly Explorer window or choose File | Open from NuGet Packages Cache in the main menu . This will open the Open from NuGet Packages Cache dialog. The dialog lists packages from all NuGet cache locations on your machine. Use the search field in the dialog to find the desired package.


1 Answers

See this pull request: Allow specifying copyToOutput and flatten as Metadata on Content items when packing sdk csproj #1450

You'll need to set PackageCopyToOutput to true in the source csproj for the content.

<Content Include="...">
    <PackageCopyToOutput>true</PackageCopyToOutput>
</Content>

and once build the package, it will include CopyToOutput="true" for that content.

like image 110
Chuanbo Avatar answered Oct 01 '22 08:10

Chuanbo