简体   繁体   中英

c# team foundation point version control server to mapped project

So in my code I have this as the setup for accessing the server item. var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://samplerepo:8080/tfs_proj/WindowsMain"), new UICredentialsProvider()); tfs.EnsureAuthenticated(); VersionControlServer vsStore = tfs.GetService<VersionControlServer>();

However when I want to create a workspace based on this server I can't. The reason is that WindowsMain isn't mapped to a local folder. However WindowsMain/MainProject is mapped to a local folder. So how can I create a workspace that is mapped to MainProject. Seeing as I cannot connect to WindowsMain/MainProject just WindowsMain since the way server connections are done with team foundation.

below code updates all files in given project. if you want to compare it could be easily modified:

private static void GetLatest(string username, string password, string path_to_download,
          string tf_src_path)
{

    Uri collectionUri = new Uri(PathConstants.uri);
    NetworkCredential credential = new NetworkCredential(username, password);
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(PathConstants.uri), credential);
    tfs.EnsureAuthenticated();
    VersionControlServer vc = tfs.GetService<VersionControlServer>();

    foreach (Workspace workspace in vc.QueryWorkspaces(null, null, System.Environment.MachineName))
        {
            foreach (WorkingFolder folder in workspace.Folders)
            {
            ItemSpec itemSpec = new ItemSpec(folder.ServerItem,  RecursionType.Full);
            ItemSpec[] specs = new ItemSpec[] { itemSpec };
            ExtendedItem[][] extendedItems = workspace.GetExtendedItems(specs, DeletedState.NonDeleted, ItemType.File);
            ExtendedItem[] extendedItem = extendedItems[0];
                foreach (var item in extendedItem)
                {
                    if (item.VersionLocal != item.VersionLatest)
                    {
                        vc.DownloadFile(item.SourceServerItem, item.LocalItem);
                    }
                }
            }
        }
    }

you can replace: vc.DownloadFile(item.SourceServerItem, item.LocalItem);

with Console.WriteLine(item.LocalItem +": needs updating");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM