TFVC api: how to get the file properties ('executable' and 'symlink')

186 views Asked by At

I have in the TFVC version control some files that are executable and others that are symlinks.

When you look at the changesets in the UI, we could see that the file has a property: script with executable property

When using the TFVC API callVersionControl.QueryHistory() with the nuget package Microsoft.TeamFoundationServer.Client, I could also see that the change corresponding to the addition of the file has a property:

file with property from API

My problem is that using the TFVC Api, I don't know how to get the properties of this change.

I want to find a way to know what is the type of this "property" change type that is included in a changeset. Especially how to know if this "property" is the "executable" property or the "symlink" one.

TFVC seems to know that a file is a symlink because it display a little different icon (notice the arrow):

icon of symlink

Type of object retrieved:

  • changeset: Microsoft.TeamFoundation.VersionControl.Client.Changeset
  • change: Microsoft.TeamFoundation.VersionControl.Client.Change
  • file/item: Microsoft.TeamFoundation.VersionControl.Client.Item (containing collections named Attributes, Properties or PropertyValues that perhaps could contains the data but that are empty)

Internet or MSDN documentation is of no help here :(

Note: The goal is to add the support to git-tfs

2

There are 2 answers

5
Levi Lu-MSFT On

You can check out the TfvcItem Class in Libray Microsoft.VisualStudio.Services.Client. TfvcItem object has IsSymbolicLink property to determine if the item is symlink or not.

You can get the ChangeSets using TfvcHttpClient object method, and then get TfvcItem object. See below example:

 string tfsurl= "http://instance/tfs/DefaultCollection";
 string Project = "project";
 
 NetworkCredential netCred = new NetworkCredential("username", @"password", "domain");
            
 Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(netCred);
     
 VssConnection _connection = new VssConnection(new Uri(tfsurl), winCred);

 TfvcHttpClient tfvcClient = _connection.GetClient<TfvcHttpClient>(); 

 var changesets = tfvcClient.GetChangesetsAsync().Result;
      
 foreach (var changeset in changesets)
 {
       var changesetRes =  tfvcClient.GetChangesetChangesAsync(changeset.ChangesetId).Result;
            
       foreach (var change in changesetRes) 
       {
          var item = (TfvcItem)change.Item;
       }
  }

See below TfvcItem object :

enter image description here

1
DGtlRift On

"Team Explorer Everywhere" somehow creates a KVP with a key named Microsoft.TeamFoundation.VersionControl.Executable in what I'm guessing is the ContentMetadata which is apparently NULL - where should this data be fetched in the API?