In TFS, versioning is controlled in the workspace workspace.
First of all, we first workspace some basic methods of use.
CheckIn: Moving to Pending operations
CreateMapping: Create a local mapping address
Delete: Remove workspace
Getpendingchanges: Getting a Pending workspace
Merge: Merging work items
Pendadd: Queued files or a folder added to the version control repository
Pendbranch: Schedule A branch of a file or folder
Penddelete: Queues Delete files or folders from the version control repository
Pendedit: Edit checkout file from version control repository
Next, we'll look at how to create a local mapping address, get a pending workspace, queue a file, move to a pending operation, and so on.
//TFSURI
Uri tfsUri = new Uri("http://pc-20130113jkun:8080/tfs");
TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(tfsUri);
//设置版本控制Server
VersionControlServer versionControl = projectCollection.GetService<VersionControlServer> ();
Set Workspace name
String workspacename = String.Format ("{0}-{1}", Environment.MachineName, "Test");
Workspace Workspace = Versioncontrol.getworkspace (workspacename, Versioncontrol.authorizeduser);
Setting Up server folders
var serverfolder = "$/calueng";
Setting up a local mapping file
var localfolder = Path.Combine ("c:\\temp\\", "Test");
Set as working directory folder
var workingfolder = new WorkingFolder (serverfolder, Localfolder);
Create a local mapping address for a workspace
Workspace. CreateMapping (WorkingFolder);
Get a workspace file and download all files
Workspace. Get ();
Create a Test folder
String NewFolder = path.combine (workspace. Folders[0]. Localitem, "Test folder");
Directory.CreateDirectory (NewFolder);
String NewFileName = Path.Combine (newfolder, "Test document 1.txt");
Create a test file
using (var StreamWriter = new StreamWriter (NewFileName))
{
Streamwriter.writeline ("This is the text of the test document");
}
Queue this file for moving into TFS management
Workspace. Pendadd (Path.getdirectoryname (NewFileName), true);
Create a collection of file items waiting to be added
var pendingadds = new list<pendingchange> (workspace. Getpendingchanges ());
To checkin a work item in a system
int changesetforadd = workspace. CheckIn (Pendingadds.toarray (), "Here is the memo message");
Console.WriteLine ("moved into work item {0}", Changesetforadd);
Console.ReadLine ();
SOURCE Download: Http://files.cnblogs.com/chengxingliang/TFSTest2.rar