热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

NugetPackager任务-未添加依赖项-NugetPackagertask-dependencyisnotadded

ImusingVisualStudioTeamServicestoautomatethecreationofanugetpackage.Thispackagehas

I'm using Visual Studio Team Services to automate the creation of a nuget package. This package has a dependency on another nuget package (Newtonsoft.Json v8.0.3). I have configured a Nuget Packager task as part of the build:

我正在使用Visual Studio Team Services自动创建nuget包。这个包依赖于另一个nuget包(Newtonsoft.Json v8.0.3)。我已将Nuget Packager任务配置为构建的一部分:

Nuget Packager task configuration

But the generated package doesn't contain the reference to the nuget package:

但生成的包不包含对nuget包的引用:

Generated nuget package without dependencies

Running the following script on my local machine to generate the package:

在我的本地计算机上运行以下脚本以生成程序包:

nuget pack myproject.csproj -Symbols -IncludeReferencedProjects -Properties COnfiguration=Release -OutputDirectory bin/Release

I can see that the dependency is added to the generated package:

我可以看到依赖项被添加到生成的包中:

Generated nuget package with dependencies

What am I missing here? Why the dependencies are not being added to to package that is being generated on the build server?

我在这里想念的是什么?为什么没有将依赖项添加到构建服务器上生成的包中?

2 个解决方案

#1


0  

"IncludeReferencedProjects" is used to add the referenced project to the nuget package, not the referenced nuget packages.

“IncludeReferencedProjects”用于将引用的项目添加到nuget包,而不是引用的nuget包。

Include referenced projects either as dependencies or as part of the package. If a referenced project has a corresponding nuspec file that has the same name as the project, then that referenced project is added as a dependency. Otherwise, the referenced project is added as part of the package. Learn more at NuGet.org.

将引用的项目包含为依赖项或作为程序包的一部分。如果引用的项目具有与项目具有相同名称的相应nuspec文件,则该引用的项目将作为依赖项添加。否则,引用的项目将作为包的一部分添加。在NuGet.org了解更多信息。

When you create the nuget package for the project which referenced to another nuget package. The nuget package dependency will be added automatically if the nupkg file exists in the packages folder. For your issue, you can add a "NuGet Installer" task in your build definition to restore the nuget package files for your solution. And then when you create the nuget package for your project, the referenced nuget package will be added as dependency.

当您为引用另一个nuget包的项目创建nuget包时。如果packages文件夹中存在nupkg文件,则会自动添加nuget包依赖项。对于您的问题,您可以在构建定义中添加“NuGet Installer”任务,以恢复解决方案的nuget包文件。然后,当您为项目创建nuget包时,引用的nuget包将作为依赖项添加。

#2


0  

I have found a solution for my problem, even though I don't understand why the package was not being created properly.

我找到了解决问题的方法,即使我不明白为什么没有正确创建包。

So basically I have 2 builds:

基本上我有2个版本:

  • a "generic" build that will compile the entire solution and run unit tests, etc (automatic, triggered on commit)
  • 一个“通用”构建,它将编译整个解决方案并运行单元测试等(自动,在提交时触发)
  • a build to generate the nuget package (manual)
  • 生成nuget包的构建(手动)

This problem is on the 2nd build. I was trying to understand what were the differences between creating the package manually on my local machine and creating the package on the build server and I realized that on the build server I was not getting the source code for the solution, only for the project folder and the .nuget folder. Given that I have more than 40 projects in the solution it makes no sense to get the whole source code for the 2nd build, right? But for some reason this is not enough to generate the nuget package properly.

这个问题是在第二次构建。我试图了解在我的本地机器上手动创建包和在构建服务器上创建包之间的区别是什么,我意识到在构建服务器上我没有获得解决方案的源代码,仅用于项目文件夹和.nuget文件夹。鉴于我在解决方案中有超过40个项目,获取第二个构建的完整源代码是没有意义的,对吧?但由于某种原因,这还不足以正确生成nuget包。

So, the solution to my problem was to get the source code for the following files/folders:

所以,我的问题的解决方案是获取以下文件/文件夹的源代码:

  • Project folder
  • 项目文件夹
  • .nuget folder (needed when restoring/installing the missing packages)
  • .nu​​get文件夹(恢复/安装缺少的软件包时需要)
  • Solution file (mysolution.sln)
  • 解决方案文件(mysolution.sln)

推荐阅读
author-avatar
heimao
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有