C#/NET公共库项目,批量打Nuget包,并上传到私有包管理仓库
参考文章:https://www.cnblogs.com/yilezhu/p/12591174.html
以下是目前个人使用的脚本:
与参考文章不同的是,每次打包完成一个项目即推送到包管理平台。
参考文件夹结构:
------nupkg(存放脚本 文件夹)
--- build_and_push_packages.ps1 (脚本文件)
------ solutionA(解决方案A 文件夹)
--- projectA (项目A 文件夹)
--- projectC (项目C 文件夹)
--- projectC (项目C 文件夹)
------ solutionB(解决方案B 文件夹)
--- projectA (项目A 文件夹)
--- projectC (项目C 文件夹)
--- projectC (项目C 文件夹)
# Paths $packFolder = (Get-Item -Path "./" -Verbose).FullName $rootFolder = Join-Path $packFolder "../" $version = "1.0.6.8" # List of solutions $solutions = ( "solutionA",
"solutionB"
) # List of projects $projects = ( "solutionA/projectA", "solutionB/projectA" ) # Create all packages foreach($project in $projects) { $projectFolder = Join-Path $rootFolder $project # Create nuget pack Set-Location $projectFolder
# 按需开启 #& dotnet clean $project.csproj -c release #& dotnet restore $project.csproj -c release #& dotnet build $project.csproj -c release & dotnet pack $project.csproj -c release -p:PackageVersion=$version # Copy nuget package $projectName = $project.Substring($project.LastIndexOf("/") + 1) $packagePath = Join-Path $projectFolder "bin/Release" Set-Location $packagePath # 填写私有包管理器地址 并填入api-key & dotnet nuget push ($projectName + "." + $version + ".nupkg") -s http://0.0.0.0:8081/repository/nuget-hosted/ --api-key "aaaaaaaaa-aaaa-aaaaaaaaa-aaaaaaaaf6e4b" } # Go back to the pack folder Set-Location $packFolder