dotnetpublish、contentFiles 和传递性 nuget 依赖项

Mat*_*son 4 msbuild nuget .net-core

是否可以从传递包依赖项复制到输出dotnet publishcontentFiles

在这个场景中,我有三个项目:

  1. 内容,其中包含nuspec
<contentFiles>
  <files include="any/any/someContent.txt" buildAction="None" copyToOutput="true" flatten="false"/>
</contentFiles>
Run Code Online (Sandbox Code Playgroud)
  1. Lib,其中有一个PackageReference内容 nuget
  2. ConsoleApp,其中有一个PackageReferenceLib nuget

Lib 项目在项目资源管理器中显示内容文件,并在构建时复制到输出,但 ConsoleApp 项目两者都不做。

我需要dotnet publish ConsoleApp.csprojsomeContent.txt内容 nuget 包含在发布输出中。

与上下文有些相关的帖子:

Jos*_*dro 6

contentFiles默认为私有资产。您需要将PrivateAssets引用中的元数据从Libto更改Content为不包含contentFiles,如下所示:

<ProjectReference Include="...">
    <PrivateAssets>analyzers;build</PrivateAssets>
</ProjectReference>
Run Code Online (Sandbox Code Playgroud)

更多信息请参见:https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets