【问题标题】:Querying TFS 2015 Source Code Repository with Powershell and Visual Studio 2019使用 Powershell 和 Visual Studio 2019 查询 TFS 2015 源代码存储库
【发布时间】:2019-08-21 16:27:10
【问题描述】:

我正在尝试使用 Visual Studio 2019 创建一个 Powershell 脚本,以访问特定的 Team Foundation Server 2015 团队项目及其分支之一。目标是返回在特定时间段内创建或修改的文件的名称。为此,我的印象是我必须过滤 .CreationTime 和 .LastWriteTime 属性。

我已使用 [Microsoft.TeamFoundation.Client] API 成功访问项目集合,但在使用版本控制存储库实例化 [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer] 时无法访问单个团队项目。已确保身份验证,但没有 vcs 方法识别存储库路径。 (我故意省略了下面代码中的程序集声明。)

    $tfsCollectionURI =[System.Uri]'http://tfs.infosys.com:8080/tfs/collection/'
    $projectsCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionURI)

   if($projectsCollection.HasAuthenticated)
  {
       $vcs = $projectsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
      }

            $projectPath = 'http://tfs.infosys.com:8080/tfs/collection/
            project/_git/Enterprise'
    $vcs.GetAllTeamProjects($true)
    $vcs.GetTeamProject('EHBs')
    $vcs.GetItems($projectPath)

【问题讨论】:

    标签: powershell tfs-2015 visual-studio-2019


    【解决方案1】:

    根据您的共享代码,您正在尝试获取错误的 projectPath。

    http://tfs.infosys.com:8080/tfs/collection/project/_git/Enterprise 这似乎是 git repo 门户网站中的一个 url。

    但是,您的代码用于 TFVC 版本控制。项目路径应该是$/MyFirstProject/Main-branch2.0-child1

    您可以使用下面的this rest api 在团队项目中查找 Git Repos:

    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}?api-version=4.1
    

    您可以使用GET Invoke-RestMethod在Powershell中执行REST API,PowerShell REST API编程请参考以下链接:

    https://wilsonmar.github.io/powershell-rest-api/

    【讨论】:

    • 我能够使用 Microsoft.TeamFoundation.SourceControl.WebAPI 库访问 GitItem 类。这将返回文件级属性。
    猜你喜欢
    • 1970-01-01
    • 2017-05-12
    • 2016-04-12
    • 1970-01-01
    • 2017-12-07
    • 2016-04-09
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    相关资源
    最近更新 更多