使用 .NET Standard 库 .csproj 时,如何将 NuGet contentFiles CopyToOutput 设置为 true? [英] How do you set NuGet contentFiles CopyToOutput to true when using a .NET Standard library .csproj?

查看:23
本文介绍了使用 .NET Standard 库 .csproj 时,如何将 NuGet contentFiles CopyToOutput 设置为 true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

使用Content节点添加文件的时候,可以看到包里面的文件,但是查看本地缓存的时候拉出来的nuspec,没有CopyToOutput,所以默认是false.在这种情况下,当它在 ASP.NET Core 站点中被引用时,不会将任何内容复制到应用程序中.如果我手动更新该缓存版本以包含该属性并将其设置为 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 an MSBuild property.

有人遇到过这个问题并有解决方法吗?

Did anybody run into this issue and has a workaround?

推荐答案

查看这个拉取请求:打包 sdk csproj #1450 时,允许指定 copyToOutput 和 flatten 作为 Content items 的 Metadata #1450

您需要在内容的源 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 Standard 库 .csproj 时,如何将 NuGet contentFiles CopyToOutput 设置为 true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆