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 a MSBuild property.
I'm hoping somebody has ran into this issue and has a work around.
see https://github.com/NuGet/NuGet.Client/pull/1450 Allow specifying copyToOutput and flatten as Metadata on Content items when packing sdk csproj
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.
@Chris I'm curious what your current nuspec looks like. In my case I'm trying to include a class file that should drop into the /controllers/api/ directory to provide a controller for standard health checks.
I would have posted this as a comment but it is too long, btw.
My references are being included properly, but for some reason the contentFiles do not copy into the consuming project when the Nuget package gets installed. Here's my current iteration:
<?xml version="1.0"?>
<package >
<metadata>
<id>Foo.Bar.Baz</id>
<version>$version$</version>
<title>title</title>
<authors>authors</authors>
<owners>owners</owners>
<description>description</description>
<tags>tags</tags>
<references>
<group targetFramework="net47">
<reference file="foo.dll" />
</group>
<group targetFramework="netstandard1.6">
<reference file="foo.dll" />
</group>
<group targetFramework="netcoreapp1.1">
<reference file="foo.dll" />
</group>
</references>
<contentFiles>
<files include="content/**/*.*" buildAction="Compile" copyToOutput="false" />
</contentFiles>
</metadata>
<files>
<file src="bin\release\netstandard1.6\foo.dll" target="lib\net47" />
<file src="bin\release\netstandard1.6\foo.dll" target="lib\netstandard1.6" />
<file src="bin\release\netstandard1.6\foo.dll" target="lib\netcoreapp1.1" />
<file src="bin\release\netstandard1.6\Content\**\*.*" target="content" />
</files>
</package>
来源:https://stackoverflow.com/questions/44073501/how-do-you-set-nuget-contentfiles-copytooutput-value-to-true-when-using-a-net-s