连接到tfs并下载VS2010中存在的文件 [英] connect to tfs and download the files present in it VS2010
本文介绍了连接到tfs并下载VS2010中存在的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想连接到TFS并下载其中包含的文件.我正在使用VS2010,并尝试了以下代码.但似乎我在某个地方出错了:
I want to connect to TFS and download the files present in it. I am using VS2010 and tried the following code. But it seems I went wrong somewhere:
对于GetItem()和CopyTo()方法,非静态字段方法需要对象引用"
"an object reference is required for the nonstatic field method" for GetItem() and CopyTo() methods
我的代码未下载所有文件.
My code is not downloading all the files.
C#代码:
static void Main(string[] args)
{
string teamProjectCollectionUrl = "https://YourTfsUrl/tfs/YourTeamProjectCollection";
string filePath = "C:\project\myfile.cs";
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
Item item = versionControlServer.GetItem(filePath, VersionSpec.Latest);
string fileString = string.Empty;
using (Stream stream = item.DownloadFile())
{
using (MemoryStream memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
using (StreamReader streamReader = new StreamReader(new MemoryStream(memoryStream.ToArray())))
{
fileString = streamReader.ReadToEnd();
}
}
}
Console.WriteLine(fileString);
Console.ReadLine();
}
有人可以帮助我获得正确的方法吗?
Could anybody please help me out getting the proper approach?
推荐答案
尝试类似的方法...
Try something like this...
static void Main(string[] args)
{
string teamProjectCollectionUrl = "http://myserver:8080/tfs/DefaultCollection";
string serverPath = "$/My Project/My SubFolder";
string localPath = @"c:\temp\download";
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
foreach (Item item in versionControlServer.GetItems(serverPath, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.Any, true).Items)
{
string target = Path.Combine(localPath, item.ServerItem.Substring(2));
if (item.ItemType == ItemType.Folder && !Directory.Exists(target))
{
Directory.CreateDirectory(target);
}
else if (item.ItemType == ItemType.File)
{
item.DownloadFile(target);
}
}
}
这篇关于连接到tfs并下载VS2010中存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文