【发布时间】:2019-08-30 18:05:55
【问题描述】:
我正在尝试筛选在特定时间段内在特定 Team Foundation Server 2015 分支上创建或修改的源代码控制文件。到目前为止,我能够通过 Microsoft.VisualStudio.Services.WebAPI 和 Microsoft.TeamFoundation.SourceControl.WebApi 库以及使用 GitHttpClient 类的 C# .Net Framework 4.8 控制台应用程序访问文件属性(例如 url)。
此类的 GetItemsAsync() 方法返回一个“GitItems”列表,其中包含一个“路径”属性,该属性可以作为参数传递到 System.IO 类 FileInfo 以实例化具有我需要的属性的对象:CreationTime和 LastWriteTime。但是,GitItem 对象不包含 FileInfo(以及 File 类)准确生成这些属性所需的完整文件 (blob) 路径。 path 属性仅包含文件名(例如 '/.gitignore')。因此,在下面的代码中,变量 lastWriteTime 和 CreationTime 属性都返回“12/31/1600 7:00:00 PM”,因为无法识别路径。
static void Main(string[] args)
{
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
VssConnection connection = new VssConnection(new Uri(teamCollection), creds);
// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
// Get data about a specific repository
var repositories = gitClient.GetRepositoriesAsync(teamProject).Result;
GitVersionDescriptor descriptor = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
Version = "develop",
VersionOptions = GitVersionOptions.None
};
foreach (var repository in repositories)
{
var branches = gitClient.GetBranchesAsync(repository.Id).Result;
var items = gitClient.GetItemsAsync(repository.Id, recursionLevel: VersionControlRecursionType.Full, versionDescriptor: descriptor, includeContentMetadata: true).Result;
foreach (var item in items)
{
var fullPath = Path.GetFullPath(item.Path);
FileInfo file = new FileInfo(fullPath);
DateTime lastWriteTime = file.LastWriteTime;
}
Console.WriteLine(repository.Name);
}
}
}
}
【问题讨论】:
-
我能够在 Powershell 中使用 Rest API v2.0 和 Invoke-RestMethod。
-
没问题(我是新手,如您所见)。 :)
标签: c# .net tfs-2015 visual-studio-2019 tfs-sdk