Azure管道构建将TFVC项目引用引入git构建

时间:2020-04-22 21:21:23

标签: azure-devops azure-pipelines

我在azure存储库中有一个git解决方案,其中有对TFVC项目的三个项目引用。我现在正在尝试使用YAML创建构建管道,但是找不到从TFVC下载项目的任何步骤。这给了我这种错误:
Error MSB3202: The project file "(path to project)\Standard.Logging.csproj" was not found

我知道这是因为项目文件夹不是存储库的一部分,但是我不确定如何将它们从tfsvc存储库导入到我的构建代理中。

这是我的azure-pipelines.yml:

pool: 'MyPool'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '$(solution)'
    feedsToUse: 'select'
    vstsFeed: '{company feed}'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" 
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

我如何下载这些项目?

1 个答案:

答案 0 :(得分:0)

恐怕YAML管道当前不支持TFVC。

作为解决方法,您可以migrate TFVC to Git

您还可以创建经典的UI构建管道,而不是YAML管道。经典UI管道支持TFVC。

enter image description here

在Yaml中支持TFVC的用户语音已提交给Microsoft开发。您可以投票或创建一个新的。参见here

更新

  • 要将tfsvc存储库中的代码带入构建代理。

您可以使用TFVC Get items rest api来获取物品。在您的管道中添加一个脚本任务,以调用其余的api并将项目保存在构建代理中。请检查以下示例powershell脚本:获取个人访问令牌。请参阅文档here

 $url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/tfvc/items?scopePath=path&recursionLevel=full&api-version=5.1"

 $PAT= "Personal access token"
 $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
 $result = Invoke-RestMethod -Uri $url -Method Get -Header @{Authorization = "Basic $base64AuthInfo"} 

 $files= $result.value | where { !$_.isFolder} | select path, url

 foreach($file in $files){
    $path = "$(System.DefaultWorkingDirectory)\" + $file.path.Substring(2)
    New-Item -Path  $path -ItemType File -Force
    Invoke-RestMethod -Uri $file.url -Method get -Header @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -OutFile $path
  }

上面的脚本调用Get Items Api并获取项目url和路径($files= $result.value | where { !$_.isFolder} | select path, url

然后获取每个项目并保存到$(System.DefaultWorkingDirectory)。例如,如果我的scopePath为$/MyProject/,则项目将保存到$(System.DefaultWorkingDirectory)/MyProject/