使用Hudson构建增加内部版本号

Tob*_*and 2 msbuild version-control hudson increment assemblyversionattribute

这是我想要实现的目标.我目前使用Hudson构建在远程计算机上为我做构建.我目前必须打开我的解决方案并手动更新两个文件中的[assembly:AssemblyVersion("1.2.6.190")]数字,然后在通过Hudson运行构建之前将我的更改提交到SVN.(除非你现在建立clcik,否则哈德森工作不会设置为运行)

我想找到一种方法,每次Hudson进行构建时自动增加最后一个数字.

我希望它增加1(没有时间戳或类似).

任何想法或其他材料的链接可能会有所帮助=)

谢谢,

托比

Nic*_*nik 5

我使用Jenkins的PowerShell插件,并使用Powershell查找匹配模式的所有文件(比如AssemblyInfo.*),然后读取文件并使用PowerShell中的内置正则表达式功能(-match和-replace操作) )查找并替换AssemblyVersion属性,将最后一个八位字节更改为当前的Jenkins内部版本号.

function assign-build-number
{
    #get the build number form Jenkins env var
    if(!(Test-Path env:\BUILD_NUMBER))
    {
        return
    }

    #set the line pattern for matching
    $linePattern = 'AssemblyFileVersion'
    #get all assemlby info files
    $assemblyInfos = gci -path $env:ENLISTROOT -include AssemblyInfo.cs -Recurse

    #foreach one, read it, find the line, replace the value and write out to temp
    $assemblyInfos | foreach-object -process {
        $file = $_
        write-host -ForegroundColor Green "- Updating build number in $file"
        if(test-path "$file.tmp" -PathType Leaf)
        {
            remove-item "$file.tmp"
        }
        get-content $file | foreach-object -process {
            $line = $_
            if($line -match $linePattern)
            {
                #replace the last digit in the file version to match this build number.
                $line = $line -replace '\d"', "$env:BUILD_NUMBER`""
            }

            $line | add-content "$file.tmp"

        }
        #replace the old file with the new one
        remove-item $file
        rename-item "$file.tmp" $file -Force -Confirm:$false
   }
}
Run Code Online (Sandbox Code Playgroud)