简体   繁体   English

使用内部版本号作为nuget-package-version

[英]Use build-number as nuget-package-version

I'm using bamboo to create nuget-packages with msbuild. 我正在用Bamboo用msbuild创建nuget包。 Currenly I always have to bump the nuget-package-version by hand before commmitting code to git (where it gets automatically build). 目前,我总是必须手动修改nuget-package-version,然后才能将代码提交给git(它会自动生成)。

I now want to use bamboo's build-number as version for the nuget-package. 我现在想使用Bamboo的内部版本号作为nuget-package的版本。

Can I change the nuget-package-version with a command-line-tool? 我可以使用命令行工具更改nuget-package-version吗?

Yes you can using Powershell. 是的,您可以使用Powershell。 I haven't tested the script, but it should do the job. 我还没有测试脚本,但是它可以完成任务。 You need to define the version number in you nuspec as $version$ and then update that during build time. 您需要在nuspec中将版本号定义为$ version $,然后在构建时进行更新。 This way you would also be able to update other information. 这样,您还可以更新其他信息。

function Update-NuspecVersion {
[CmdletBinding()]
param(
    [Parameter()]
    [string]$RootFolder = $(throw "Repo folder is mandatory, please provide a value."),

    [Parameter()]
    [int]$BuildNumber
)

$Nuspecs  = Get-ChildItem -Path $RootFolder -Recurse  -Filter *.nuspec | Where-Object { $_.FullName -notlike "*\obj\*"}
Foreach ($Nuspec in $Nuspecs) {
    $nuspecfile = [xml]$(Get-Content $Nuspec.FullName)
    $PackageVersion = $([xml]$(Get-Content $Nuspec.FullName) | % package).metadata.version
    if ($PackageVersion -eq '$version$') {  
        $Assembly = get-childitem $nuspec.Directory -Recurse -Filter "AssemblyInfo.Version.cs"
        if ($Assembly.Count -eq 0) {
            $Assembly = get-childitem $nuspec.Directory -Recurse -Filter "AssemblyInfo.cs"
        }
        $PackageVersion = $(Get-content $Assembly.FullName | ForEach-Object { $_ -replace '\/\/.+', ""; } | Select-String "AssemblyVersion").ToString().Split('"')[1]
    }

    $PackageVersionObject=[version]$PackageVersion
    if ($Branch.Type -eq "develop") {
        $PackageVersion ="{0}.{1}.{2}-{3}-{4}" -f $PackageVersionObject.major, $PackageVersionObject.Minor,  $BuildNumber, $Branch.Type, ("{0:D4}" -f  $BuildNumber) 
    }
    else {
        $PackageVersion ="{0}.{1}.{2}" -f $PackageVersionObject.major, $PackageVersionObject.Minor,  $BuildNumber
    }

    $nuspecfile.package.metadata.version = $PackageVersion
    $nuspecfile.Save($Nuspec.FullName)
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM