如何在Visual Studio Team Services中作为构建的一部分签入文件?

Ric*_*los 6 powershell team-build azure-devops

我试图弄清楚如何在我们的构建过程中关闭循环,我们将版本号应用于AssemblyInfo.*文件作为构建过程的一部分.

我们正处于从内部部署tfs迁移到视觉工作室团队服务的过程中.我们当前的许多内部部署版本都会更新版本号以使其与内部版本号保持同步,并在构建期间将这些文件再次检入源代码管理中.

我已成功使用位于msdn上脚本作为示例来开始自定义构建过程.

我现在正试图检查文件回到源代码管理,但我收到错误:

#[error]TF30063: You are not authorized to access https://subdomain.visualstudio.com/DefaultCollection.
#[error]Process completed with exit code 100 and had 1 error(s) written to the error stream.
Run Code Online (Sandbox Code Playgroud)

我目前正在使用tf.exe尝试这样做.首先获取powershell脚本顶部的工具路径;

# get the tf command line tool path
$tfexe = [System.IO.Path]::GetFullPath($env:VS140COMNTOOLS + "..\..\common7\ide\tf.exe")
if (-Not (Test-Path $tfexe))
{
    Write-Error "Could not find tf.exe at '$tfexe'"
    exit 1
}
else
{
    Write-Host "Found tf.exe at '$tfexe'"
}
Run Code Online (Sandbox Code Playgroud)

然后修改循环以签出文件,然后重新检入文件.

# Apply the version to the assembly property files
$files = gci $Env:BUILD_SOURCESDIRECTORY -recurse -include "*Properties*","My Project" | 
    ?{ $_.PSIsContainer } | 
    foreach { gci -Path $_.FullName -Recurse -include AssemblyInfo.* }
if($files)
{
    Write-Host "Will apply $NewVersion to $($files.count) files."

    foreach ($file in $files) {

        #Write-Host "Attempting to checkout file '$file'"
        & ($tfexe) vc checkout $file

        $filecontent = Get-Content($file)
        attrib $file -r
        $filecontent -replace $VersionRegex, $NewVersion | Out-File $file
        Write-Host "$file.FullName - version applied"
    }

    # Checkin pending changes together
    ##[error]TF30063: You are not authorized to access https://subdomain.visualstudio.com/DefaultCollection.
    ##[error]Process completed with exit code 100 and had 1 error(s) written to the error stream.
    Write-Host "Attempting to checkin files"
    $comment = "Applied $NewVersion to $($files.count) files.  ***NO_CI***"
    & ($tfexe) vc checkin /comment:"$comment" /noprompt
}
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?如果构建服务没有被授权访问,那么它是如何获取代码,编译它,然后在某个地方发布工件?

jes*_*ing 6

我不建议每次都检查汇编版本,而是建议使用[assembly: AssemblyVersion("1.2.*")]通配符支持(我删除它[AssemblyFileVersion]所以它自动匹配.

在构建之后以多种方式检查已更改的文件:

  • 索引源和符号功能将使用与变更集关联的代码不匹配的源.这将破坏高级调试方案.
  • 高级测试功能中断,可能会建议不需要的测试或更改集
  • 历史堆满了**NO_CI**变更
  • 它破坏了语义版本控制,因为这些类型的脚本不会破坏API更改并可能导致有趣的行为.

我创建了一个新的构建任务,它允许您使用任务签入文件:

使用tfx控制台将其添加到visualstudio团队基础服务或TFS 2015实例:

tfx build tasks upload -taskpath path\to\project\root
Run Code Online (Sandbox Code Playgroud)

我仍在研究添加和删除的方法,但是我遇到了客户端对象模型的问题,除了编辑之外没有任何其他问题.

它看起来像调用,tf add并且tf delete实际上将在构建脚本中与此签入任务结合使用.

欲获得更多信息: