2014-12-02 60 views
0

我目前正致力于更新我们公司Team Foundation Server上模板的程序。我在我的磁盘上使用了本地新模板,并且想要替换服务器上的现有模板。我尝试了不同的方法,这是我的最新版本。问题是,无论是通过C#替换TFS中具有相同名称但内容不同的新文件的文件

  1. 通过在C#编码访问它时(不使用时,当我尝试使用正常的资源管理器来取代它在运行时)新的文件是“使用”。

  2. 替换未出现在未决更改中,pendingChanges数组为初始值。

    using (var tfs = TeamFoundationServerFactory.GetServer("myserver")) 
        { 
         var versionControlServer = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer; 
    
         // Create a new workspace for the currently authenticated user.  
    
         var workspace = versionControlServer.CreateWorkspace("Temporary Workspace", versionControlServer.AuthorizedUser); 
    
         try 
         { 
          // Check if a mapping already exists. 
          var workingFolder = new WorkingFolder("$serverpath", @"c:\tempFolder"); 
    
          // Create the mapping (if it exists already, it just overides it, that is fine). 
          workspace.CreateMapping(workingFolder); 
          workspace.Get(VersionSpec.Latest, GetOptions.GetAll); 
    
          string[] paths = new string[1]; 
          paths[0] = "test.pdf"; 
    
          workspace.PendEdit(paths, RecursionType.Full, null, LockLevel.None); 
    
    
          // Go through the folder structure defined and create it locally, then check in the changes. 
          CreateFolderStructure(workspace, workingFolder.LocalItem); 
    
          // Check in the changes made.      
          int a = workspace.CheckIn(workspace.GetPendingChanges(), "This is my comment"); 
         } 
         catch (Exception ex) 
         { 
          Console.WriteLine(ex.Message); 
         } 
         finally 
         { 
          // Cleanup the workspace. 
          workspace.Delete(); 
    
          // Remove the temp folder used. 
          Directory.Delete(@"C:\tempFolder", true); 
         } 
        } 
    } 
    
    static void CreateFolderStructure(Workspace workspace, string initialPath) 
    {    
        workspace.PendDelete("$serverpath/test.pdf", RecursionType.None); 
    
        File.Copy(@"C:\test\testnew.pdf", @"C:\tempfolder\test", true); 
        workspace.PendAdd(@"C:\tempfolder\test.pdf"); 
    } 
    

回答