Azure DevOps Server 的连接源(Artifacts):二、NuGet包管理

1. 环境准备

1.1 nuget.exe概述

  • 概述
    nuget.exe是nuget的命令工具(cli),通过 CLI 工具可轻松更新和还原项目和解决方案中的 NuGet 包。 该工具提供 Windows 上的所有 NuGet 功能以及 Mac 和 Linux 上在 Mono 下运行时的大多数功能。

  • 使用范围
    nuget.exe CLI 适用于 .NET Framework 项目和非 SDK 样式项目(例如,面向 .NET Standard 库的非 SDK 样式项目)。

1.1 安装nuget.exe

  • 从官方网站(https://www.nuget.org/downloads )下载nuget.exe文件,也可以从连接源的连接中导航到官方下载网站
  • image
  • 将文件保存到本地计算机的任意目录,并将这个目录添加到环境变量PATH 中
  • 可以在命令行中运行nuget,查看工具的所有参数
  • image

2. 常用功能

2.1 install

install 命令使用指定的包源将包下载并安装到项目中,默认为当前文件夹。 将新包安装到项目根目录的“包”文件夹中。

nuget install <packageID> -OutputDirectory packages

例如

nuget install helloworld -OutputDirectory helloworld
C:\temp>nuget install microsoft.teamfoundationserver.client -outputdirectory tfs-client
Feeds used:
  https://api.nuget.org/v3/index.json
  C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Installing package 'microsoft.teamfoundationserver.client' to 'C:\temp\tfs-client'.
  CACHE https://api.nuget.org/v3/registration5-gz-semver2/microsoft.teamfoundationserver.client/index.json


Attempting to gather dependency information for package 'microsoft.teamfoundationserver.client.16.170.0' with respect to project 'C:\temp\tfs-client', targeting 'Any,Version=v0.0'
Gathering dependency information took 1.45 sec
Attempting to resolve dependencies for package 'microsoft.teamfoundationserver.client.16.170.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'microsoft.teamfoundationserver.client.16.170.0'
Resolved actions to install package 'microsoft.teamfoundationserver.client.16.170.0'
Retrieving package 'Microsoft.AspNet.WebApi.Client 5.2.7' from 'nuget.org'.
Retrieving package 'Microsoft.AspNet.WebApi.Core 5.2.7' from 'nuget.org'.
Retrieving package 'Microsoft.AspNet.WebApi.WebHost 5.2.7' from 
<省略。。。。。>
folder 'C:\temp\tfs-client'
Added package 'Microsoft.TeamFoundationServer.Client.16.170.0' to folder 'C:\temp\tfs-client'
Successfully installed 'Microsoft.TeamFoundationServer.Client 16.170.0' to C:\temp\tfs-client
Executing nuget actions took 3.92 sec

C:\temp>

例如我们在目录AzureDevOps\webapi\webapi目录下执行下面的命令,将项目中依赖的模块(packages.config中指定的模块)都下载到了上一级目录packages文件夹中:

nuget install packages.config -outputdirectory ../packages

特别注意:

install 命令不会修改项目文件或 packages.config;在这种方式下,它类似于 restore,因为它只向磁盘添加包,而不更改项目的依赖项。 
要添加依赖项,请通过 Visual Studio 中的包管理器 UI 或控制台添加包,或修改 packages.config,然后运行 或 restore。

2.2 安装特定版本的程序包

如果在使用 install 命令时未指定版本,NuGet 将安装最新版本的包。 还可以安装特定版本的 Nuget 包:

nuget install microsoft.teamfoundationserver.client -Version 16.170.0

2.3 移除包

要删除一个或多个包,请从“包”文件夹中删除要删除的包。

如果要重新安装包,请使用 restore 或 install 命令。


3. 相关文章

如果需要,你还可以从微软Azure DevOps Server 的在线文档,查询更多的权威资料,也欢迎通过下面的联系方式与我沟通,相互学习,相互提高!


https://www.cnblogs.com/danzhang
Azure DevOps MVP 张洪君
在这里插入图片描述

posted on 2022-03-13 09:56  danzhang  阅读(246)  评论(0编辑  收藏  举报

导航