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

前面我创建了一个非常简单的类库,这边我不做过多叙述,接下来我们需要进行编辑csproj文件,当我们创建Nuget包时,我们将使用dotnet pack命令。这于传统的Nuget cli稍微有点不同,在传统的Nuget CLI中,我们创建nuspec文件并针对nuspec运行nuget packdotnet 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程序包的更多相关文章

  1. 【Azure DevOps系列】使ASP.NET Core应用程序托管到Azure Web App Service

    使用Azure DevOps Project设置ASP.NET项目 我们需要先在Azure面板中创建一个Azure WebApp服务,此处步骤我将省略,然后点击部署中心如下图所示: 此处我选择的是Az ...

  2. 流程自动化RPA,Power Automate Desktop系列 - DotNet Core打包并发布Nuget Package

    一.背景 DotNet Core通常基于Nuget来实现包管理,如果你想要把自己的实现共享给其他人,通常我们需要把本地项目打包好,然后发布到对应的Nuget Server上,以便于其他人可以查找.安装 ...

  3. Azure Redis Cache作为ASP.NET 缓存输出提供程序

    前一篇文章<Azure Redis Cache作为ASP.NET Session状态提供程序 >我们已经知道如何将ASP.NET应用程序Session存储在Redis Cache中,这里我 ...

  4. Azure Redis Cache作为ASP.NET Session状态提供程序

    从上一篇博客<使用Azure Redis Cache>我们已经可以创建并使用Redis Cache为我们服务了. 作为Web开发者,我们都知道Session状态默认是保存在内存中的,它的优 ...

  5. 使用VS中自带的一键打包功能将我们的ASP.NET Core类库打包并将程序包(类库)发布到NuGet平台上进行管理

    本章将和大家简单分享下如何使用VS中自带的一键打包功能将我们的ASP.NET Core类库打包并将程序包(类库)发布到NuGet平台上进行管理. 一.注册并登录NuGet平台 NuGet官网:http ...

  6. 利用 Azure Devops 创建和发布 Nuget 包

    利用 Azure Devops 创建和发布 Nuget 包 原 Visual Studio Team Service ,简称 VSTS,能够创建 pipelines 管道以构建应用程序,并将其部署到任 ...

  7. 【Azure DevOps系列】什么是Azure DevOps

    DevOps DevOps是一种重视"软件开发人员(Dev)"和"IT运维技术人员(Ops)"之间沟通合作的文化,它促进开发和运营团队之间的协作,以自动化和可重 ...

  8. Azure DevOps to Azure AppServices

    Azure DevOps is a complete solution for software development, from planning to building to deploymen ...

  9. [Azure Devops] 使用 Azure Boards 管理工作

    1. 什么是 Azure Boards 通过 Azure Boards 网络服务,团队可以管理其软件项目.它提供了丰富的功能,包括 Scrum 和看板的本地支持.可定制的仪表板和集成报告.这些工具可以 ...

随机推荐

  1. java_流程控制语句、权限修饰符

    判断语句 if语句第一种格式: if if(关系表达式){ 语句体; } if语句第二种格式: if…else if(关系表达式) { 语句体1; } else { 语句体2; } if语句第三种格式 ...

  2. Mac 系统更新怎么忽略

    1.在“终端”命令行中输入以下命令: sudo softwareupdate --ignore “macOS Catalina” 2.按回车键,然后输入管理员密码*,然后再次按回车键,以超级用户权限执 ...

  3. salesforce零基础学习(九十九)Git 在salesforce项目中的应用(vs code篇)

    本篇参考: https://code.visualstudio.com/docs/editor/versioncontrol https://git-scm.com/doc https://git-s ...

  4. js 打开新窗体

    function nw(repId,formulaId){ if(!repId){ repId='0' } if(!formulaId){ formulaId='0' } var url='/slsi ...

  5. Vue 给子组件绑定v-model

    父组件使用子组件时,使用v-model指令,在子组件中使用value获取props的值 父组件 <template> <div style="margin:20px;dis ...

  6. CentOS7基于ss5搭建Socks5代理服务器

    简介 环境 节点名 IP 软件版本 硬件 网络 说明 falcon-binary 172.19.0.6 list 里面都有 2C4G Nat,内网 测试环境 部署 准备编译环境和依赖 #安装编译环境和 ...

  7. 树上的等差数列 [树形dp]

    树上的等差数列 题目描述 给定一棵包含 \(N\) 个节点的无根树,节点编号 \(1\to N\) .其中每个节点都具有一个权值,第 \(i\) 个节点的权值是 \(A_i\) . 小 \(Hi\) ...

  8. sql server 查询表字段的说明备注信息

    SELECT 表名 = case when a.colorder= then d.name else '' end, 表说明 = case when a.colorder= then isnull(f ...

  9. MySQL 偶尔抽风,性能突然下降

    有时会碰到这样的情况,一条 SQL 在平时执行没问题,很快.但是突然某个时间执行的就会很慢,而且这种场景并不能复现,只能随机发送的. SQL 执行突然变慢的原因 在之前讲解 MySQL Redo lo ...

  10. docker入门2-docker service

    docker service介绍 service是生产环境中某个image的container集合.一个service只使用一个image,但它编排这个image的运行方式,比如使用哪个端口,根据需求 ...