问题描述
我一直在寻找将.net标准库项目中VS2017中内置的nuget包中包含的内容文件的CopyToOutput属性设置为true的任何方法.
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.
使用内容"节点添加文件时,我可以看到包中的文件,但是当查看在本地缓存时被拉出的nuspec时,没有CopyToOutput,因此默认情况下为false.在这种情况下,当它在asp.net核心站点中被引用时,不会将任何内容复制到应用程序中.如果我手动更新该缓存版本以包括该属性并将其设置为true并还原,则所有内容都会被复制.
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.
不幸的是,我调查了Nuget.Build.Tasks.Pack.dll,看来没有办法通过MSBuild属性传递该值.
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.
推荐答案
请参见 https://github.com/NuGet/NuGet.Client/pull/1450 打包sdk csproj时,允许在内容项上指定copyToOutput并将其展平为元数据
see https://github.com/NuGet/NuGet.Client/pull/1450 Allow specifying copyToOutput and flatten as Metadata on Content items when packing sdk csproj
您需要在源csproj中将内容的 PackageCopyToOutput 设置为true.
You'll need to set PackageCopyToOutput to true in the source csproj for the content.
<Content Include="...">
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
并一旦构建了程序包,它将为该内容包含CopyToOutput ="true".
and once build the package, it will include CopyToOutput="true" for that content.
这篇关于使用.Net标准库.csproj时,如何将nuget contentFiles CopyToOutput值设置为true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!