1. 程式人生 > 其它 >Azure DevOps Server 的連線源(Artifacts):二、NuGet包管理

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檔案,也可以從連線源的連線中導航到官方下載網站
  • 將檔案儲存到本地計算機的任意目錄,並將這個目錄新增到環境變數PATH 中
  • 可以在命令列中執行nuget,檢視工具的所有引數

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 的連線源(Artifacts):一、概述
  • Azure DevOps Server 的連線源(Artifacts):二、nuget包管理
  • Azure DevOps Server 的連線源(Artifacts):三、從Artifacts中下載Nuget包
  • Azure DevOps Server 的連線源(Artifacts):四、python基礎(Django、Flask)
  • Azure DevOps Server 的連線源(Artifacts):五、python包管理pip和twine
  • Azure DevOps Server 的連線源(Artifacts):六、釋出python程式(Twine pip)
  • Azure DevOps Server 的連線源(Artifacts):七、從Artifact中下載python程式包
  • Azure DevOps Server 的連線源(Artifacts):八、NPM 基礎知識
  • Azure DevOps Server 的連線源(Artifacts):九、npm釋出和安裝包
  • Azure DevOps Server 的連線源(Artifacts):十、vue示例和自動打包(npm node)

如果需要,你還可以從微軟Azure DevOps Server 的線上文件,查詢更多的權威資料,也歡迎通過下面的聯絡方式與我溝通,相互學習,相互提高!


https://www.cnblogs.com/danzhang
Azure DevOps MVP 張洪君