msbuild - dotnet publish、contentFiles 和可传递的 nuget 依赖项

标签 msbuild nuget .net-core

dotnet publish 是否可以将 contentFiles 复制到传递包依赖项的输出?

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

  1. 内容,其中有一个 nuspec 包含:
<contentFiles>
  <files include="any/any/someContent.txt" buildAction="None" copyToOutput="true" flatten="false"/>
</contentFiles>
  1. Lib,它有一个 PackageReference 到 Content nuget
  2. ConsoleApp,它有一个指向 Lib nuget 的 PackageReference

Lib 项目在项目资源管理器中显示 contentFiles 并在构建时复制到输出,但 ConsoleApp 项目两者都没有。

我需要 dotnet publish ConsoleApp.csproj 在发布输出中包含 Content nuget 中的 someContent.txt

上下文相关的帖子:

最佳答案

contentFiles 默认是私有(private) Assets 。您需要将引用中的 PrivateAssets 元数据从 Lib 更改为 Content,以便它不包含 contentFiles,像这样:

<ProjectReference Include="...">
    <PrivateAssets>analyzers;build</PrivateAssets>
</ProjectReference>

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

关于msbuild - dotnet publish、contentFiles 和可传递的 nuget 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45970316/

相关文章:

asp.net-mvc-3 - vs12 不再支持 CopyAllFilesToSingleFolderForPackageDependsOn

asp.net - 基于 GIT 的 asp.net Web 应用程序无法部署到 Azure,并出现 typescript 编译错误

asp.net-core - 如何创建和访问Session .net core api?

json - 将 json 数据传递给 ASP.Net core 2 web api

c# - 来自文本文件变量的 csproj 文件中的多个提示路径

c# - 当我从 msbuild 构建解决方案时未构建 Visual Studio 项目

windows - 使用 Chocolatey 创建自己的包

push - 405 NuGet 推送中不允许使用方法

c# - NuGet pack 命令如何生成包版本?

c# - EF Core 查询在真实数据库中运行良好,但测试失败