Jenkins~powershell+cmd发布nuget包包
nuget包也要自动化部署了,想想确实挺好,在实施过程中我们要解决的问题有版本自动控制,nuget自动打包,nuget自动上传到服务端等。
一 参数化构建

二 环境变量的k/v参数,存储类库的初始版本,当根目录version.txt生成后,这个k/v就不需要了

三 这个构建跳转到哪台节点服务器

四 使用ps插件,完成version.txt的建立和更新

$initVersion=[Environment]::GetEnvironmentVariable("${env:projectName}") #版本文件目录 $VersionFileDirectory="${env:WORKSPACE}/NugetServices/${env:projectName}" #版本文件名字 $VersionFileName="version.txt" #版本文件路径 $VersionFilePath="$VersionFileDirectory\$VersionFileName" #初始版本变量值 1.0.0.0 $InitVersionValue="100"; #版本长度1.0.0.0 =4 $VersionLength=3 Function UpdateVersion($vvalue,$vlength,$vfilepath) { $content=$(Get-Content -Path $vfilepath) if([string]::IsNullOrEmpty($content)) { Write-Host "version file don't exist ,creating version file......" SetVersion $vvalue $vlength $vfilepath } else { $versionvalue=$([string]$content) Write-Host "old version: $versionvalue" $versionvalues=$([int]([string]$versionvalue).Replace(".","")) $versionvalues=$(($versionvalues+1).ToString()) SetVersion $versionvalues $vlength $vfilepath } } #设置版本值,版本名,版本值,版本长度,版本文件路径 Function SetVersion($vvalue,$vlength,$vfilepath) { if(-Not (Test-Path -Path $vfilepath)) { $null=New-Item -Path $vfilepath -ItemType File -Force } $value=GetVersion $vvalue $vlength Set-Content -Path $vfilepath -Value "$value" } Function GetVersion($value,$versionlength) { $value=[string]$value $versionlength=[int]$versionlength $versionvalue=""; $num=$value.Length-$versionlength+1 for($i=0;$i -lt $versionlength;$i++) { if($i -eq 0) { $versionvalue= $value.Substring(0,$num)+"." } else { $index=$i+$num-1 $versionvalue=$versionvalue+$value[$index]+"." } } $result=$versionvalue.Trim("."); Write-Host "new version: $result" return $result; } if(-Not(Test-Path -Path $VersionFilePath)) { SetVersion $initVersion $VersionLength $VersionFilePath } else { UpdateVersion $InitVersionValue $VersionLength $VersionFilePath }
五 使用cmd,完成.net core项目的发布和打包,注意如果是frameworks项目,需要使用nuget.exec 完成这个功能。
NGUET方法:(nuget pack NugetServices/Pilipa.Utility -version 2.1.3)
path "C:\Program Files\dotnet" cd "NugetServices/%projectName%" set /p version=<version.txt dotnet restore --configfile ../../NuGet.Config dotnet build dotnet pack -o nugets /p:version=%version% dotnet nuget push nugets/%projectName%.%version%.nupkg -k abc123 -s https://nugetserver.i-counting.cn/
好了,以上就是我在nuget打包实现自动化部署的过程!
感谢阅读!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库