C# TFS API“没有工作文件夹 C:\TFS”在VS2008安装的系统中

发布于 2024-12-20 21:45:19 字数 2324 浏览 4 评论 0原文

我想找出最近使用 C# 和 TFS2010 中的 TFS API 签入的文件。在安装了 MS Visual studio 2010 的地方它工作得很好。这是使用VS2010、.Net 3.5开发的。

当我在安装了 VS2008 的系统中使用此 exe 时,会抛出错误“*没有工作文件夹 C:\TFS*。

  • 本系统只有3.5 Framework。
  • 我从 C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0 复制了所有文件以及可执行文件。
  • C:\TFS 是实际的映射文件夹。甚至还尝试了内部文件夹。

请提出任何建议。 有没有办法在不考虑本地映射的情况下从 TFS 获取结果?

TeamFoundationServer tfsServer = new TeamFoundationServer("http://snchndevtfsapp:8080/tfs/defaultcollection");
WorkItemStore workItemStore = new WorkItemStore(tfsServer);
VersionControlServer vcServer = tfsServer.GetService(typeof(VersionControlServer)) as VersionControlServer;
var usersWorkspaces = vcServer.QueryWorkspaces(null, vcServer.AuthorizedUser, Environment.MachineName).ToList();

List<ChangedTFSItem> foundPastChanges = new System.Collections.Generic.List<ChangedTFSItem>();

var allPastChangesets = vcServer.QueryHistory(@"C:\TFS",
                                              VersionSpec.Latest,
                                              0,
                                              RecursionType.Full,
                                              null,
                                              null,
                                              null,
                                              1000,
                                              true,
                                              false).Cast<Changeset>();
//.Where(x => x.Committer.Contains(Environment.UserName));


List<ChangedTFSItem>  _foundPastChanges = allPastChangesets
    .SelectMany(x => x.Changes)
    .Where(x => x.Item.CheckinDate.Date >= ((DateTime)dateEdit1.EditValue))
    //.DistinctBy(x => x.Item.ServerItem, x => x.Item.ServerItem.GetHashCode())
    .Select(x => new ChangedTFSItem()
        {
            FileName = Path.GetFileName(x.Item.ServerItem),
            ServerItem = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem).Replace(textEdit1.Text, ""),
            LocalPath = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem),
            ChangeTypeName = x.ChangeType.ToString(),
            ChangeDate = x.Item.CheckinDate.ToString()
        }).ToList();

I want to find out the files recently checked in using C# and TFS API from TFS2010. It works fine where MS Visual studio 2010 is installed. this is developed using VS2010, .Net 3.5.

When I use this exe in system having VS2008 installed throws error as "*There is no working folder C:\TFS"*.

  • This system has only 3.5 Framework.
  • I copied all the files from C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0 along with executable.
  • C:\TFS is the actual mapping folder. Even tried inner folder as well.

any suggestion please. is there any way to get result from TFS without considering local mappings?

TeamFoundationServer tfsServer = new TeamFoundationServer("http://snchndevtfsapp:8080/tfs/defaultcollection");
WorkItemStore workItemStore = new WorkItemStore(tfsServer);
VersionControlServer vcServer = tfsServer.GetService(typeof(VersionControlServer)) as VersionControlServer;
var usersWorkspaces = vcServer.QueryWorkspaces(null, vcServer.AuthorizedUser, Environment.MachineName).ToList();

List<ChangedTFSItem> foundPastChanges = new System.Collections.Generic.List<ChangedTFSItem>();

var allPastChangesets = vcServer.QueryHistory(@"C:\TFS",
                                              VersionSpec.Latest,
                                              0,
                                              RecursionType.Full,
                                              null,
                                              null,
                                              null,
                                              1000,
                                              true,
                                              false).Cast<Changeset>();
//.Where(x => x.Committer.Contains(Environment.UserName));


List<ChangedTFSItem>  _foundPastChanges = allPastChangesets
    .SelectMany(x => x.Changes)
    .Where(x => x.Item.CheckinDate.Date >= ((DateTime)dateEdit1.EditValue))
    //.DistinctBy(x => x.Item.ServerItem, x => x.Item.ServerItem.GetHashCode())
    .Select(x => new ChangedTFSItem()
        {
            FileName = Path.GetFileName(x.Item.ServerItem),
            ServerItem = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem).Replace(textEdit1.Text, ""),
            LocalPath = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem),
            ChangeTypeName = x.ChangeType.ToString(),
            ChangeDate = x.Item.CheckinDate.ToString()
        }).ToList();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-12-27 21:45:19

不要将物理路径作为查询历史记录 @"C:\TFS" 中的第一个参数,而是尝试使用源代码管理路径。如果对所有变更集感兴趣,只需放置根 "$/"

对于您想要完成的任务,您可以通过执行以下操作来跳过任何本地工作区连接:

using System;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace GetFilesOfLatestChangesets
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS_URI"));
            var vcS = teamProjectCollection.GetService(typeof (VersionControlServer)) as VersionControlServer;
            var changesets =
                vcS.QueryHistory("$/", VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 10, true, false).
                    Cast<Changeset>();
            foreach (var changeset in changesets)
            {
                Console.WriteLine("Changes for "+changeset.ChangesetId);
                foreach (var change in changeset.Changes)
                {
                   Console.WriteLine(change.Item.ServerItem); 
                }
            }  
        }
    }
}

但随后您将检索已更改模块的服务器路径,而不是它们在工作站中映射的位置。

最后一点:您必须使用 includeChanges = true 来查询历史记录,因此请求最后的 1000 变更集应该相当昂贵。

Instead of placing a physical path as your first argument in Query History @"C:\TFS", try using a source control path. If are interested in all changesets, simply place the root "$/".

For the task you are trying to accomplish, you can skip any local workspace connection by doing something like this:

using System;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace GetFilesOfLatestChangesets
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS_URI"));
            var vcS = teamProjectCollection.GetService(typeof (VersionControlServer)) as VersionControlServer;
            var changesets =
                vcS.QueryHistory("$/", VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 10, true, false).
                    Cast<Changeset>();
            foreach (var changeset in changesets)
            {
                Console.WriteLine("Changes for "+changeset.ChangesetId);
                foreach (var change in changeset.Changes)
                {
                   Console.WriteLine(change.Item.ServerItem); 
                }
            }  
        }
    }
}

but then you 'll retrieve the server paths for the changed modules and not where they have been mapped in your workstation.

One final remark: You have to QueryHistory with includeChanges = true, therefore asking for the last 1000 changesets should be rather expensive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文