Compartilhar via


Extending Version Control

You can extend Team Foundation version control by accessing and updating items on the server and in a workspace on the local computer.

In this topic

Observação

You can also create custom check-in policies and apply them to a team project. For more information, see the following page on the Microsoft Web site: How to: Create Custom Check-in Policies.

Example: Accessing Items on the Server

The following sample uses the VersionControlServer object to list every version of the .xaml files on the server.

To use this example

  1. Create a console application.

  2. Add references to the following assemblies:

  3. Replace the contents of Program.cs with this example.

using System; 
using System.Text; 
using Microsoft.TeamFoundation.Client; 
using Microsoft.TeamFoundation.Framework; 
using Microsoft.TeamFoundation.VersionControl.Client; 

namespace VCSample
{
    class Program
    {
        static void Main(string[] args) 
        {
            // Connect to the team project collection, and get the version control server. 
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
               new Uri("https://Server:8080/tfs/DefaultCollection"));
            VersionControlServer vcServer = tpc.GetService<VersionControlServer>(); 

            // List all of the .xaml files.
            ItemSet items = vcServer.GetItems("$/*.xaml", RecursionType.Full); 
            foreach(Item item in items.Items) 
            {
                Console.Write(item.ItemType.ToString());
                Console.Write(": ");
                Console.WriteLine(item.ServerItem.ToString());
            }
        }
    }
}

Example: Update Items in a Workspace

You can work with files in a workspace by performing operations such as get, check out, and check in. The following example gets the most recent version of the files in a workspace.

To use this example

  1. Replace the section of code that lists the .xaml files in the previous example with the following code.

  2. Replace the WorkspaceName with the name of the workspace, which is typically the same as the name of the computer that contains the workspace.

  3. Replace UserName with the fully qualified user name of the workspace owner.

For more information, see Workstation.GetLocalWorkspaceInfo and Set Up your Development Machine to Work with your Team's Project.

// Get the workspace that is mapped to c:\BuildProcessTemplate
WorkspaceInfo wsInfo = Workstation.Current.GetLocalWorkspaceInfo(
   vcServer, @"WorkspaceName", @"UserName");
Workspace ws = vcServer.GetWorkspace(wsInfo); 

// Update the workspace with most recent version of the files from the server
GetStatus status = ws.Get();
Console.Write("Conflicts: ");
Console.WriteLine(status.NumConflicts);

You can also get a workspace that is mapped to a folder on the local computer by passing the full path of that folder to Workstation.GetLocalWorkspaceInfo.

WorkspaceInfo wsInfo = Workstation.Current.GetLocalWorkspaceInfo(@"c:\MyWorkspace");

See Also

Concepts

Extending Team Foundation

Other Resources

Using Version Control