powershell - 使用 Powershell 和 Visual Studio 2019 查询 TFS 2015 源代码存储库
问题描述
我正在尝试使用 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)
解决方案
根据您的共享代码,您正在尝试获取错误的 projectPath。
http://tfs.infosys.com:8080/tfs/collection/project/_git/Enterprise
这似乎是 git repo 门户网站中的一个 url。
但是,您的代码用于TFVC 版本控制。项目路径应该是$/MyFirstProject/Main-branch2.0-child1
您可以使用下面的这个 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 编程,请参考以下链接:
推荐阅读
- amazon-web-services - DynamoDB 模式设计支持按 ID 和时间戳查找项目?
- phpmailer - 服务器 SMTP PHPMailer 的问题
- angular - 使用 jasmine 和量角器运行 e2e 测试时捕获控制台错误
- php - 尽管在本地成功,但在 Circleci 上构建失败
- javascript - Blockstack 应用程序在 npm install ERR 上失败!配置错误
- c++ - 使用 OpenCV 的 CMake 模块目标而不是直接包含所有库?
- .net - 使用 PowerShell 连接到 Azure FTP 但在 C# 中工作时出现错误 501
- parsing - 为什么我们在编译器中同时需要预读符号和预读符号
- android - 片段管理器添加错误的片段
- c# - AQMP ReceiverLink 失去连接