如何增加汇编信息和签入(提交)到源代码管理

时间:2015-10-04 16:12:07

标签: .net tfs build-process tfs2015

在TFS 2015提供的新构建系统中,您将如何完成增加程序集版本的任务,但将其检入源控件

我希望在AssemblyInfo文件中编写的源代码控制中始终提供当前版本。

1 个答案:

答案 0 :(得分:0)

下面的PowerShell脚本(引自此blog)修改TF_BUILD_SOURCESDIRECTORY目录中AssemblyInfo.cs文件中的AssemblyVersion和AssemblyFileVersion值。

不要自己测试,你可以尝试添加一个目标到承载AssemblyInfo.cs的服务器路径的变量,并用它替换TF_BUILD_SOURCESDIRECTORY。

Param(
  [string]$pathToSearch = $env:TF_BUILD_SOURCESDIRECTORY,
  [string]$buildNumber = $env:TF_BUILD_BUILDNUMBER,
  [string]$searchFilter = "AssemblyInfo.*",
  [regex]$pattern = "\d+\.\d+\.\d+\.\d+"
)
 
try
{
    if ($buildNumber -match $pattern -ne $true) {
        Write-Host "Could not extract a version from [$buildNumber] using pattern [$pattern]"
        exit 1
    } else {
        $extractedBuildNumber = $Matches[0]
        Write-Host "Using version $extractedBuildNumber"
 
        gci -Path $pathToSearch -Filter $searchFilter -Recurse | %{
            Write-Host "  -> Changing $($_.FullName)"
         
            # remove the read-only bit on the file
            sp $_.FullName IsReadOnly $false
 
            # run the regex replace
            (gc $_.FullName) | % { $_ -replace $pattern, $extractedBuildNumber } | sc $_.FullName
        }
 
        Write-Host "Done!"
    }
}
catch {
    Write-Host $_
    exit 1
}