在使用.Net标准库.csproj时,如何将nuget contentFiles CopyToOutput值设置为true?

问题描述 投票:4回答:2

我一直在寻找任何方法将内容文件的CopyToOutput属性设置为true,我将其包含在VS2017中从.Net标准库项目构建的nuget包中。

使用Content节点添加文件时,我可以看到包中的文件,但是当查看在本地缓存时拔出的nuspec没有CopyToOutput,所以默认情况下它是false。在这种情况下,当它在asp.net核心站点中引用时,不会将任何内容复制到应用程序中。如果我手动更新该缓存版本以包含该属性并将其设置为true并恢复,则会复制所有内容。

不幸的是,我查看了Nuget.Build.Tasks.Pack.dll,看起来没有办法通过MSBuild属性传递该值。

我希望有人遇到过这个问题并且有一个解决方法。

asp.net-core nuget csproj
2个回答
5
投票

请参阅https://github.com/NuGet/NuGet.Client/pull/1450在打包sdk csproj时允许指定copyToOutput并在内容项上展平为元数据

您需要在内容的源csproj中将PackageCopyToOutput设置为true。

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

并且一旦构建了包,它将包含该内容的CopyToOutput =“true”。


0
投票

@Chris我很好奇你现在的nuspec是什么样的。在我的情况下,我正在尝试包含一个应该放入/ controllers / api /目录的类文件,以便为标准运行状况检查提供控制器。

我会发布这个评论,但它太长了,顺便说一下。

我的引用被正确包含,但由于某种原因,在安装Nuget包时,contentFiles不会复制到使用项目中。这是我当前的迭代:

<?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>
© www.soinside.com 2019 - 2024. All rights reserved.