如何在TFS中探索Source Control文件夹? [英] How to explore Source Control folder in TFS?

查看:45
本文介绍了如何在TFS中探索Source Control文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有没有人尝试使用控制台应用程序连接到TFS源控制文件夹?


-Soniya


解决方案

Hi snyprsnmay2013,



感谢您在此发帖。



您可以使用  versioncontrolserver  对象
来获取和浏览控制台应用程序中源代码管理下的文件,您可以参考以下示例:

 

使用System;
使用Microsoft.TeamFoundation.Client;
使用Microsoft.TeamFoundation.VersionControl.Client;
使用System.IO;

命名空间ConsoleApplication1
{
class程序
{
static void Main(string [] args)
{

//文件路径必须在源代码管理中具有工作文件夹映射
string teamProjectCollectionUrl =" http:// v-tinmo-12r2:8080 / tfs / DefaultCollection2015U3" ;;
string filePath = @" C:\Users\Test \Source \ Workspaces \ TestGao1 \ConsoleApplication1 \ConsoleApplication1 \Program.cs" ;;

//获取版本控制服务器
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
VersionControlServer versionControlServer = teamProjectCollection.GetService< VersionControlServer>();

//获取filePath
的最新项目Item item = versionControlServer.GetItem(filePath,VersionSpec.Latest);

//下载并显示内容到控制台
string fileString = string.Empty;

使用(Stream stream = item.DownloadFile())
{
using(MemoryStream memoryStream = new MemoryStream())
{
stream.CopyTo (MemoryStream的);

//使用StreamReader读取从字节数组
创建的MemoryStream(StreamReader streamReader = new StreamReader(new MemoryStream(memoryStream.ToArray())))
{
fileString = streamReader.ReadToEnd();
}
}
}

Console.WriteLine(fileString);
Console.ReadLine();
}
}
}

详细信息,您可以参考以下链接:


https://paulselles.wordpress.com/2014/01/08/team-foundation-server-api-programmatically-downloading-files-from-source-control/


同时查看以下博客:


http://blogs.microsoft.co.il/shair/2009/02/26/tfs-api-part- 16-mapping-source-control-using-versioncontrolserver /



最好的问候


Limitxiao Gao


Hi,

Has anyone tried to connect to TFS source control folder using console application?

-Soniya

解决方案

Hi snyprsnmay2013,

Thank you for posting here.

You could use the versioncontrolserver object to get and explorer the files under source control in console application, you could refer to the following sample:

using System; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.VersionControl.Client; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) {

//The filepath must have working folder map in source control string teamProjectCollectionUrl = "http://v-tinmo-12r2:8080/tfs/DefaultCollection2015U3"; string filePath = @"C:\Users\Test\Source\Workspaces\TestGao1\ConsoleApplication1\ConsoleApplication1\Program.cs"; // Get the version control server TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl)); VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>(); // Get the latest Item for filePath Item item = versionControlServer.GetItem(filePath, VersionSpec.Latest); // Download and display content to console string fileString = string.Empty; using (Stream stream = item.DownloadFile()) { using (MemoryStream memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); // Use StreamReader to read MemoryStream created from byte array using (StreamReader streamReader = new StreamReader(new MemoryStream(memoryStream.ToArray()))) { fileString = streamReader.ReadToEnd(); } } } Console.WriteLine(fileString); Console.ReadLine(); } } }

For detailed information, you could refer to the following link:

https://paulselles.wordpress.com/2014/01/08/team-foundation-server-api-programmatically-downloading-files-from-source-control/

Also check the following blog:

http://blogs.microsoft.co.il/shair/2009/02/26/tfs-api-part-16-mapping-source-control-using-versioncontrolserver/

Best Regards

Limitxiao Gao


这篇关于如何在TFS中探索Source Control文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆