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

How do you checkin files as part of the build in Visual Studio Team Services?

我正在尝试找出如何关闭构建过程中的循环,在构建过程中,我们将版本号应用于 AssemblyInfo.* 文件。

我们正在从本地 tfs 迁移到 visual studio 团队服务。我们当前的许多本地构建更新版本号以使其与构建号保持同步,并在构建期间将这些文件重新检入源代码管理。

我已经成功使用 script located on 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.

我目前正在使用 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'"
}

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

# 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
}

这是执行此操作的正确方法吗?如果构建服务没有被授权访问,它怎么能获取代码,编译它,然后 POST 某个地方的工件?

正如我之前评论的那样。

I would rather discard the changes on AssemblyInfo.* files than check them into the source control.

在我的例子中,我使用 1.$(date:yy).$(date:MMdd)$(rev:.r) 作为内部版本号格式

所以我永远不会从 AssemblyInfo.* 文件中读回版本,那么保存这些信息有什么意义呢?

无论 AssemblyInfo.*

存储的值如何,内部版本号格式都会再次生成版本

如果您想将源代码与特定版本同步,您可以使用相同的内部版本号格式来标记源代码。

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

构建后签入更改的文件有多种方式:

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

我创建了一个新的构建任务,它将允许您使用任务 check-in 文件:

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

tfx build tasks upload -taskpath path\to\project\root

我仍在研究挂起添加和删除的方法,但我 运行 遇到了客户端对象模型的问题,除了编辑之外,我没有挂起任何东西。

看起来调用 tf addtf delete 将在构建脚本中结合此签入任务实际工作。

更多信息: