• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c#获取TFS结构文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
#region 获取最新版本

        /// <summary>
        /// 获取最新版本
        /// </summary>
        /// <param name="server_url">http://192.168.3.202:8080/tfs/projectcollection_single</param>
        /// <param name="server_path">$/TP_publish/WebSln_Test_For_Publish/WebTest</param>
        /// <param name="loacl_path">E:\Tfs\Project_Collection_Single</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public static bool GetLastVersionByPath(string server_url, string loacl_path)
        {
            var teamProjects = new TfsTeamProjectCollection(new Uri(server_url));
            var teamVersion = teamProjects.GetService<VersionControlServer>();
            //Workspace workspace = teamVersion.GetWorkspace(loacl_path);
            var workspace = teamVersion.GetWorkspace(System.Net.Dns.GetHostName(), teamVersion.AuthorizedUser);//参数1 工作区名称,默认电脑名称
            workspace.Get();

            return true;
        }
        #endregion
获取最新版本
#region 获取集合 解决方案 项目

        public void Init()
        {
            Uri tfsUri = new Uri(this.TfsUrl);

            //TFS配置服务获取所有项目的名称和所有的团队集合名称
            TfsConfigurationServer configserver = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
            ReadOnlyCollection<CatalogNode> collectNodes = configserver.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);

            this.Collotion = new List<Model.Collotion>();
            foreach (CatalogNode collect in collectNodes)
            {
                Guid collectid = new Guid(collect.Resource.Properties["InstanceId"]);
                TfsTeamProjectCollection teamproject = configserver.GetTeamProjectCollection(collectid);

                var collotion = new Model.Collotion()//集合
                {
                    Name = collect.Resource.DisplayName,
                    Path = teamproject.Uri.Host + "\\" + collect.Resource.DisplayName,
                    Url = teamproject.Uri.ToString(),
                    Solution = new List<Model.Solution>()
                };

                var teamVersion = teamproject.GetService<VersionControlServer>();
                var workspace = teamVersion.GetWorkspace(Dns.GetHostName(), teamVersion.AuthorizedUser);
                var folders = workspace.Folders;

                foreach (var folder in folders)
                {
                    var items = teamVersion.GetItems(folder.ServerItem, RecursionType.Full).Items;
                    var arr = items.Where(ex => ex.ServerItem.EndsWith(".sln")).ToList();

                    foreach (var item in arr)//解决方案
                    {
                        if (teamVersion.GetItems(item.ServerItem.Substring(0, item.ServerItem.LastIndexOf("/")), RecursionType.Full).Items.Where(ex => ex.ServerItem.EndsWith("Web.config")).Count() > 0)
                        {
                            var solution = new Model.Solution()
                            {
                                Name = Path.GetFileName(item.ServerItem),
                                Path = item.ServerItem,
                                Url = collotion.Url,
                                Project = new List<Model.Project>()
                            };

                            var dirPath = System.IO.Path.GetDirectoryName(item.ServerItem).Replace("\\", "/") + "/";
                            var projects = items.Where(ex => ex.ServerItem.StartsWith(dirPath) && ex.ServerItem.EndsWith(".csproj")).ToList();
                            foreach (var project in projects)//项目
                            {
                                if (teamVersion.GetItems(project.ServerItem.Substring(0, project.ServerItem.LastIndexOf("/")), RecursionType.Full).Items.Where(ex => ex.ServerItem.EndsWith("Web.config")).Count() > 0)
                                {
                                    solution.Project.Add(new Model.Project()
                                    {
                                        Name = Path.GetFileName(project.ServerItem),
                                        Path = project.ServerItem,
                                        Url = collotion.Url,
                                        mappingPath = workspace.GetWorkingFolderForServerItem(project.ServerItem).LocalItem
                                    });
                                }
                            }
                            collotion.Solution.Add(solution);
                        }
                    }
                }
                Collotion.Add(collotion);
            }
        }
        #endregion
获取集合 解决方案 项目

代码下载:

没找到上传文件的地方:qq 674613047


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#ADO连接数据库发布时间:2022-07-13
下一篇:
使用C#实现ADSL自动拨号发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap