Find all locked files in TFS

前端 未结 5 1098
粉色の甜心
粉色の甜心 2021-02-04 03:48

I would like to see all files that are locked. so far, I\'ve only found to use tf.exe status and look for anything with \'!\' because they are not reported as \"lock, edit\" as

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 03:53

    I don't think this is possible using tf.exe or even tfpt.exe (The Power Tool command line). You'll need to look through the pending changesets for changes that are locks. You could do this in powershell using the Power Tool commandlets or you could do it using the following bit of .NET code that exercises the TFS API:

    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.VersionControl.Client;
    
    namespace TfsApiExample
    {
      class Program
      {
        static void Main(string[] args)
        {
          GetLockedFiles("http://tfsserver:8080","$/TeamProject");
        }
    
        private static void GetLockedFiles(string serverUrl, string serverPath)
        {
          TeamFoundationServer tfs = new TeamFoundationServer(serverUrl);
          VersionControlServer vcServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
    
          // Search for pending sets for all users in all 
          // workspaces under the passed path.
          PendingSet[] pendingSets = vcServer.QueryPendingSets(
              new string[] { serverPath }, 
              RecursionType.Full, 
              null, 
              null);
    
          Console.WriteLine(
              "Found {0} pending sets under {1}. Searching for Locks...",
              pendingSets.Length, 
              serverPath);
    
          foreach (PendingSet changeset in pendingSets)
          {
            foreach(PendingChange change in changeset.PendingChanges)
            {
              if (change.IsLock)
              {
                // We have a lock, display details about it.
                Console.WriteLine(
                    "{0} : Locked for {1} by {2}",
                    change.ServerItem, 
                    change.LockLevelName, 
                    changeset.OwnerName);
              }
            }
          }
    
        }
      }
    }
    

提交回复
热议问题