如何以编程方式将文件从本地文件夹签入到TFS?

时间:2012-10-31 11:35:19

标签: tfs tfs2010 tfsbuild

任何人都可以帮我解决如何从本地文件夹中检查文件集(特别是* .dll文件)到本地文件夹的问题。实际上,一旦在构建中创建了构建,我就需要一组项目服务器我必须将此构建的输出更新为TFS中的公共程序集文件夹。此程序集由各种应用程序使用。我们正在使用TFS 2010构建定义进行构建自动化。

1 个答案:

答案 0 :(得分:1)

我已经通过以下代码找到了这个......

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();