如何使用 Team Foundation Server SDK 获取最新版本的源代码?
我正在尝试使用 SDK 以编程方式从 TFS 中提取最新版本的源代码,但我所做的不知何故不起作用:
string workspaceName = "MyWorkspace";
string projectPath = "/TestApp";
string workingDirectory = "C:\Projects\Test\TestApp";
VersionControlServer sourceControl; // actually instantiated before this method...
Workspace[] workspaces = sourceControl.QueryWorkspaces(workspaceName, sourceControl.AuthenticatedUser, Workstation.Current.Name);
if (workspaces.Length > 0)
{
sourceControl.DeleteWorkspace(workspaceName, sourceControl.AuthenticatedUser);
}
Workspace workspace = sourceControl.CreateWorkspace(workspaceName, sourceControl.AuthenticatedUser, "Temporary Workspace");
try
{
workspace.Map(projectPath, workingDirectory);
GetRequest request = new GetRequest(new ItemSpec(projectPath, RecursionType.Full), VersionSpec.Latest);
GetStatus status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); // this line doesn't do anything - no failures or errors
}
finally
{
if (workspace != null)
{
workspace.Delete();
}
}
该方法基本上是使用 Get() 方法来获取该项目的所有项目,然后删除工作区。这是执行此操作的正确方法吗?任何例子都会有帮助。
I'm attempting to pull the latest version of source code out of TFS programmatically using the SDK, and what I've done somehow does not work:
string workspaceName = "MyWorkspace";
string projectPath = "/TestApp";
string workingDirectory = "C:\Projects\Test\TestApp";
VersionControlServer sourceControl; // actually instantiated before this method...
Workspace[] workspaces = sourceControl.QueryWorkspaces(workspaceName, sourceControl.AuthenticatedUser, Workstation.Current.Name);
if (workspaces.Length > 0)
{
sourceControl.DeleteWorkspace(workspaceName, sourceControl.AuthenticatedUser);
}
Workspace workspace = sourceControl.CreateWorkspace(workspaceName, sourceControl.AuthenticatedUser, "Temporary Workspace");
try
{
workspace.Map(projectPath, workingDirectory);
GetRequest request = new GetRequest(new ItemSpec(projectPath, RecursionType.Full), VersionSpec.Latest);
GetStatus status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); // this line doesn't do anything - no failures or errors
}
finally
{
if (workspace != null)
{
workspace.Delete();
}
}
The approach is basically creating a temporary workspace, using the Get()
method to grab all the items for this project, and then removing the workspace. Is this the correct way to do this? Any examples would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我最终使用了一种似乎有效的不同方法,主要利用
Item.DownloadFile()
方法:I ended up using a different approach that seems to work, mainly taking advantage of the
Item.DownloadFile()
method:我完成了代码并将其实现为一个按钮作为 web asp.net 解决方案。
为了使项目在引用中工作,应添加
Microsoft.TeamFoundation.Client
和Microsoft.TeamFoundation.VersionControl.Client
引用,并在代码中添加语句using Microsoft.TeamFoundation.Client;
和使用 Microsoft.TeamFoundation.VersionControl.Client;
I completed and implemented the code into a button as web asp.net solution.
For the project to work in the references should be added the
Microsoft.TeamFoundation.Client
andMicrosoft.TeamFoundation.VersionControl.Client
references and in the code the statementsusing Microsoft.TeamFoundation.Client;
andusing Microsoft.TeamFoundation.VersionControl.Client;
你的方法是有效的。
您的错误出现在您的项目路径中。使用类似这样的东西:
Your approach is valid.
Your error is in your project path. Use something like this instead:
我同意 Joerage 的观点,你的服务器路径可能是罪魁祸首。为了更深入地了解正在发生的情况,您需要在 VersionControlServer 对象上连接一些事件。至少您需要 Getting、NonFatalError 和 Conflict。
完整列表: http: //msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver_events(VS.80).aspx
I agree with Joerage that your server path is probably the culprit. To get more insight into what's happening, you need to wire up some events on the VersionControlServer object. At minimum you'll want Getting, NonFatalError, and Conflict.
Complete list: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver_events(VS.80).aspx
我遇到过类似的情况,我需要将“a”文件夹的内容从 tfs 下载到现有工作区,而不创建新的工作区。在上述答案的帮助下,我能够将一些目前对我来说很好用的东西组合在一起。然而有一个限制。这适用于仅包含文件的“a”文件夹的内容,而不适用于其中的其他文件夹 - 我还没有尝试过。也许这会涉及一些小的更新。共享代码,以防万一有人正在搜索此代码。我真的很喜欢这种方法不处理工作区[-创建和删除],因为这是不希望的。
从命令提示符运行此程序时,复制所有支持的 dll 以及 exe
cmd>>
DownloadFolder.exe“$///” “C:\MyTempFolder”
I had a similar situation where I needed to download contents of 'a' folder from tfs into an existing workspace, without creating a new workspace. With help from the above answers, I was able to put something together that works fine for me as of now. There is however a limitation. This works for contents of 'a' folder with just files and not another folder inside it -I have not tried that out. Maybe that would involve some minor updates. Sharing code, just in case someone is searching for this. I really like the fact that this approach does not deal with workspace [-create and delete], since that is not desired.
While running this from the command prompt copy all the supporting dlls along with exe
cmd>>
DownloadFolder.exe "$/<TeamProject>/<FirstLevelFolder>/<SecondLevelFolder>" "C:\MyTempFolder"