【Azure DevOps系列】Azure DevOps构建并发布Nuget程序包
在Azure DevOps中,管道可以用来构建解决方案,O(∩_∩)O哈哈~快万能了,本章主要介绍如何创建Nuget包并且将其发布到Nuget服务器的过程。

前面我创建了一个非常简单的类库,这边我不做过多叙述,接下来我们需要进行编辑csproj文件,当我们创建Nuget包时,我们将使用dotnet pack命令。这于传统的Nuget cli稍微有点不同,在传统的Nuget CLI中,我们创建nuspec文件并针对nuspec运行nuget pack。dotnet pack命令将从csproj创建一个nuspec文件,然后将代码打包到一个nupkg文件中,需要将一些关键信息添加到csproj文件中,以确保它可以正确的创建Nuget包。首先我们需要一个PackageId,这将是Nuget包本身的名称,根据我们要发布的位置这个名称必须是唯一的,接下来是Version,它将是已发布的软件包的版本号,正如下所示是我们的csproj文件
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>AzureDevOpsTest.Common</PackageId>
<Version>1.0.0</Version>
<Authors>HueiFeng</Authors>
<Description>Test project of common utils</Description>
<IsPackable>true</IsPackable>
</PropertyGroup>
</Project>
我们需要在Azure DevOps中创建项目,并进行git仓库的绑定,当绑定完之后我们先来创建相关的服务账号信息,步骤如下所示:



构建项目(dotnet build)
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
打包项目(dotnet pack)
使用nobuild意味着在运行pack之前不会编译项目,因为它已经在上面的步骤中构建了
- task: DotNetCoreCLI@2
displayName: "dotnet pack"
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: '**/*.csproj'
nobuild: true
versioningScheme: 'off'
发布项目(nuget push)
如下所示这种方式适合在Azure DevOps组织内的制品库,当然在制品库中可以设置可见性,我们可以设置对该程序包的公开和私有。allowPackageConflicts:true代表在版本重复的情况下,可以进行跳过重复的版本,避免返回409。但是这种方式在Nuget.exe中无法进行使用,这将避免不了返回409影响我们流水线的正常性。我们只能进行选择通过dotnet nuget push的方式进行忽略并发布,下面第二个代码片段所写。
对于这个问题其实我寻求过答案,但是团队这边给出的是:
I have discussed this with the team and we have decided not to add this functionality to the task. Instead of using these "bulkier" tasks we now recommend using the NuGet Authenticate task to authenticate to Azure DevOps Artifacts feeds and to use a script task with nuget/dotnet to use the parameters you need.
The reason for this is that the NuGet/Dotnet clients are actively being developed and new parameters and functionality are being added often. To keep up with all of the updates causes a lot of extra support for these bulky tasks. Please use example above to set up your pipeline with the '--skip-duplicate' parameter. Thank you for understanding.
这是痛苦的这将代表我们无法通过如下这种很简单的方式不得不选择通过dotnet nuget push进行发布,不太清真了。。。
- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'hueifeng_nuget'
allowPackageConflicts: true
- task: DotNetCoreCLI@2
displayName: "dotnet push"
inputs:
command: 'custom'
custom: 'dotnet nuget push $(Build.ArtifactStagingDirectory)/**/*.nupkg -k $(APIKey) -s https://api.nuget.org/v3/index.json --skip-duplicate'
Reference
https://github.com/hueifeng/AzureDevOpsDemo/tree/demo03
【Azure DevOps系列】Azure DevOps构建并发布Nuget程序包的更多相关文章
- 【Azure DevOps系列】使ASP.NET Core应用程序托管到Azure Web App Service
使用Azure DevOps Project设置ASP.NET项目 我们需要先在Azure面板中创建一个Azure WebApp服务,此处步骤我将省略,然后点击部署中心如下图所示: 此处我选择的是Az ...
- 流程自动化RPA,Power Automate Desktop系列 - DotNet Core打包并发布Nuget Package
一.背景 DotNet Core通常基于Nuget来实现包管理,如果你想要把自己的实现共享给其他人,通常我们需要把本地项目打包好,然后发布到对应的Nuget Server上,以便于其他人可以查找.安装 ...
- Azure Redis Cache作为ASP.NET 缓存输出提供程序
前一篇文章<Azure Redis Cache作为ASP.NET Session状态提供程序 >我们已经知道如何将ASP.NET应用程序Session存储在Redis Cache中,这里我 ...
- Azure Redis Cache作为ASP.NET Session状态提供程序
从上一篇博客<使用Azure Redis Cache>我们已经可以创建并使用Redis Cache为我们服务了. 作为Web开发者,我们都知道Session状态默认是保存在内存中的,它的优 ...
- 使用VS中自带的一键打包功能将我们的ASP.NET Core类库打包并将程序包(类库)发布到NuGet平台上进行管理
本章将和大家简单分享下如何使用VS中自带的一键打包功能将我们的ASP.NET Core类库打包并将程序包(类库)发布到NuGet平台上进行管理. 一.注册并登录NuGet平台 NuGet官网:http ...
- 利用 Azure Devops 创建和发布 Nuget 包
利用 Azure Devops 创建和发布 Nuget 包 原 Visual Studio Team Service ,简称 VSTS,能够创建 pipelines 管道以构建应用程序,并将其部署到任 ...
- 【Azure DevOps系列】什么是Azure DevOps
DevOps DevOps是一种重视"软件开发人员(Dev)"和"IT运维技术人员(Ops)"之间沟通合作的文化,它促进开发和运营团队之间的协作,以自动化和可重 ...
- Azure DevOps to Azure AppServices
Azure DevOps is a complete solution for software development, from planning to building to deploymen ...
- [Azure Devops] 使用 Azure Boards 管理工作
1. 什么是 Azure Boards 通过 Azure Boards 网络服务,团队可以管理其软件项目.它提供了丰富的功能,包括 Scrum 和看板的本地支持.可定制的仪表板和集成报告.这些工具可以 ...
随机推荐
- 025_go语言中的通道同步
代码演示 package main import "fmt" import "time" func worker(done chan bool) { fmt.P ...
- Django 环境下常用的模型设计
Django 环境下常用的模型设计 用户表 继承 django.contrib.auth.model import AbstractUser AbstractUser 默认已经包含了很多字段了 id ...
- ZooKeeper Watcher 机制
前言 在 ZooKeeper 中,客户端可以向服务端注册一个监听器,监听某个节点或者其子节点列表,当监听对象发生变化时,服务端就会向指定的客户端发送通知,这是 ZooKeeper 中的 Watcher ...
- C#LeetCode刷题之#860-柠檬水找零(Lemonade Change)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4036 访问. 在柠檬水摊上,每一杯柠檬水的售价为 5 美元. 顾 ...
- C#算法设计排序篇之08-计数排序(附带动画演示程序)
计数排序(Counting Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/689 访问. 计数排序是一个非基 ...
- C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4005 访问. 给定两个大小为 m 和 n 的有序数组 nums1 ...
- JavaScript 循环数组的时候调用方法中包含Promise的时候如何做到串行
forEach是不能阻塞的, 默认[并行]方式 const list = [1, 2, 3] const square = num => { return new Promise((resolv ...
- CentOS7基于ss5搭建Socks5代理服务器
简介 环境 节点名 IP 软件版本 硬件 网络 说明 falcon-binary 172.19.0.6 list 里面都有 2C4G Nat,内网 测试环境 部署 准备编译环境和依赖 #安装编译环境和 ...
- golang的 strconv 包
前言 不做文字搬运工,多做思路整理 就是为了能速览标准库,只整理我自己看过的...... 注意!!!!!!!!!! 单词都是连着的,我是为了看着方便.理解方便才分开的 1.strconv 中文文档 [ ...
- [源码解析] Flink UDAF 背后做了什么
[源码解析] Flink UDAF 背后做了什么 目录 [源码解析] Flink UDAF 背后做了什么 0x00 摘要 0x01 概念 1.1 概念 1.2 疑问 1.3 UDAF示例代码 0x02 ...