【问题标题】:Copy dependency assemblies into nuget package将依赖程序集复制到 nuget 包中
【发布时间】:2020-12-06 16:27:15
【问题描述】:

我得到了一个包含许多 .Net Standard 2.0 项目的 VS 2019 解决方案。 我的主项目有一个项目依赖于另一个项目,该项目依赖于一个 Dapper 程序集。 将主项目编译成 NuGet 包后,该包没有得到 Dapper 依赖。 如何将 Dapper 程序集包含到 NuGet 包中?

【问题讨论】:

  • 当你打包你的主项目时,它会将another project作为一个nuget包但是你没有打包another project,所以它会在包源和它的内容上错过another package另一个包,包括Dapper
  • 所以我的建议是你也应该把你的another project打包成nuget包,然后放入nuget package source
  • 实际上,Drapper 程序集存在于another project 包下,并没有显示在主项目中,而是显示在another project 依赖项中,并与主项目一起安装依赖项目。

标签: visual-studio dependencies nuget nuget-package


【解决方案1】:

将依赖程序集复制到nuget包中

当您打包您的主项目时,它会将another project 制作为一个nuget 包,因为main project 引用another project。您应该注意dotnet pack 会将another project 视为一个nuget 包,但您没有另外打包another project

所以它将错过包源上的another project,并且依赖关系Dapper存在于another project下。

它不在主项目的依赖中,而是在另一个项目的依赖包中。

建议

================================================ ===========

1) 你不用太担心。您还应该将another project打包为 nuget 包,然后将其放入nuget package source

像这样:

虽然依赖Dapper没有显示在主项目上,它显示在依赖包下。并与依赖项目一起安装到项目中。

================================================ ======

请注意

在安装任何版本的包之前,你应该先clean nuget caches first或删除C:\Users\xxx(current user)\.nuget下的缓存包文件夹

================================================ ==========

2) 如果你还想在主项目下看到依赖Dapper,你也应该安装Dapper nuget包到主项目。

然后打包就可以看到里面的依赖Dapper了。

================================================ ==========

另外,如果你不希望引用的项目成为依赖nuget包,而只是一个程序集dll,你可以参考this link's solution

【讨论】:

    猜你喜欢
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多