zaheer abbas
zaheer abbas

Reputation: 353

How to check in files from local folder to TFS programatically?

Can anyone help me how to checkin set of files (especially *.dll files) to TFS from local folder which is not mapped locally.Actually i am having an requirement for a set of projects once the build is created in the build server i have to update the output of this build to a common assemblies folder in the TFS.Where this assemblies are used by various applications.Here we are using the TFS 2010 build definition for build automation.

Upvotes: 0

Views: 1675

Answers (1)

zaheer abbas
zaheer abbas

Reputation: 353

I have figured out this by below code .....

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsName));
// Get a reference to Version Control.              
VersionControlServer versionControl = tfs.GetService<VersionControlServer>();
Workspace workspace = 
    versionControl.CreateWorkspace("TempWorkSpace1", versionControl.AuthorizedUser);               

// Create a mapping using the Team Project supplied on the command line.
workspace.Map(tfsPath, path);
context.WriteBuildMessage("Sucessfully mapped to the folder " + path, 
    BuildMessageImportance.High);
// Get the files from the repository.

workspace.Get();
context.WriteBuildMessage("Sucessfully get the binaries from workspace", 
    BuildMessageImportance.High);

String files = tfsPath + "/*";

context.WriteBuildMessage(
    "Temporarily checking out the files from tfs path " + files, 
    BuildMessageImportance.High);

int pendedit = workspace.PendEdit(files, RecursionType.Full);

PendingChange[] pendingchanges = workspace.GetPendingChanges();

context.WriteBuildMessage(
    "Copying all the binaries from the DropLocation- " + 
    buildInformation.DropLocation, 
    BuildMessageImportance.High);

CopyAllFiles(buildInformation.DropLocation, path, false);

context.WriteBuildMessage("Copied all the binaries from the DropLocation", 
    BuildMessageImportance.High);

WorkspaceCheckInParameters parameters = 
    new WorkspaceCheckInParameters(pendingchanges, "***NO_CI***")
    {
        OverrideGatedCheckIn = true,
    };

int changeset = workspace.CheckIn(parameters);

context.WriteBuildMessage("Checking in all the files to workspace - " + tfsPath, 
    BuildMessageImportance.High);

// Cleanup the workspace.
workspace.Delete();      
DeleteMappedFolder();

Upvotes: 1

Related Questions