How do you set nuget contentFiles CopyToOutput value to true when using a .Net Standard library .csproj?

社会主义新天地 提交于 2019-12-01 16:34:18

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!