简体   繁体   English

使用TFS API C#从TFS中的文件读取内容

[英]Read content from file which is in TFS with TFS API C#

Maybe is duplicate but I didn't find proper answer. 也许是重复的,但我没有找到正确的答案。

Is it possible to read content from file which is on TFS before MSBuild is started? 在启动MSBuild之前是否可以从TFS上的文件中读取内容?

I am using following: 我正在使用以下:

 TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("https://hasinc.visualstudio.com/DefaultCollection"));
 VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;   
 Item item = version.GetItem(@"$\SomeProject\SomeFile.cs");

I provided server path and I retrieved correct "item". 我提供了服务器路径,并检索了正确的“项目”。 I can read some properties eg content length. 我可以阅读一些属性,例如内容长度。 But how I can read file? 但是如何读取文件?

I need to read content and extract some specific info! 我需要阅读内容并提取一些特定信息!

That process happening during TFS build in custom activity method: 该过程在TFS内建自定义活动方法期间发生:

protected override void Execute(CodeActivityContext context)
{
}

Is it possible to achieve that? 有可能实现这一目标吗?

Some ideas on downloading the file: 有关下载文件的一些想法:

DownloadFile Method DownloadFile方法

You could use the DownloadFile method to download the file to a temporary file: 您可以使用DownloadFile方法将文件下载到临时文件:

TfsTeamProjectCollection server = new TfsTeamProjectCollection(new Uri("https://hasinc.visualstudio.com/DefaultCollection"));
VersionControlServer version = server.GetService(typeof(VersionControlServer)) as VersionControlServer;   
Item item = version.GetItem(@"$\SomeProject\SomeFile.cs");
string tempFileName = System.IO.Path.GetTempFileName();
item.DownloadFile(tempFileName);

DownloadFiles Activity DownloadFiles活动

Rather than getting the file in a custom activity, Team Build 2012 & 2013 both support a DownloadFiles activity , which allows a customized build to download file(s) not in the workspace. Team Build 2012和2013都支持DownloadFiles活动 ,而不是通过自定义活动获取文件,该活动允许自定义版本下载不在工作空间中的文件。

Add an Extra Path to the Build Source Settings 向构建源设置添加额外的路径

You could edit the Source Settings of your build definition, to map an additional source control folder to a build agent folder. 您可以编辑构建定义的“ 源设置” ,以将其他源控制文件夹映射到构建代理文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM