Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

asp.net core - How do you set NuGet contentFiles CopyToOutput to true when using a .NET Standard library .csproj?

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 an MSBuild property.

Did anybody run into this issue and has a workaround?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See this pull request: Allow specifying copyToOutput and flatten as Metadata on Content items when packing sdk csproj #1450

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...