-->

Get list of files from tfs changeset

2019-07-29 07:53发布

问题:

I need to get a list of changed files from chageset only and exclude all other junk.

I can get this information from the command tf changeset /i $(changesetnumber) but besides of List of files i have a lot of other information which I dont need for my purposes.

Or maybe someone can tell how to get this list of files from ccnet so I can send it to my msbuild.proj file via property.

回答1:

You could use the TFS API to get the information you want. Here's some example C# code that will select the file names of all edited, added and deleted files

Uri serverUri = new Uri("http://mytfsserver:8080/");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(serverUri);
tpc.EnsureAuthenticated();
VersionControlServer vcs = tpc.GetService<VersionControlServer>();
var changeset = vcs.GetChangeset(changesetId);
var changedFiles = from change in changeset.Changes where
       (  (change.ChangeType & ChangeType.Edit) == ChangeType.Edit
       || (change.ChangeType & ChangeType.Add) == ChangeType.Add
       || (change.ChangeType & ChangeType.Delete) == ChangeType.Delete)
     select change.Item.ServerItem;

I'm afraid I haven't used cc.net so can't advise on the best way to integrate this into ccnet, but you could compile it into a small utility or rewrite it in a scripting language (e.g. Powershell, IronPython)



回答2:

You could use CCNET's Modification Writer Task. Put it to your CCNET configuration's <prebuild> section and process the generated file in your <msbuild> task:

<Project DefaultTargets="Go" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Go">
    <XmlPeek
      XmlInputPath="$(CCNetArtifactDirectory)\modifications.xml"
      Query="/ArrayOfModification/Modification">
      <Output TaskParameter="Result" ItemName="Modifications" />
    </XmlPeek>
    <MSBuild
      Projects="$(MSBuildProjectFile)"
      Properties="Modification=%(Modifications.Identity)"
      Targets="MessageModificationPath">
    </MSBuild>
  </Target>
  <Target Name="MessageModificationPath">
    <XmlPeek
      XmlContent="$(Modification)"
      Query="/Modification/FolderName/text()">
      <Output TaskParameter="Result" PropertyName="FolderName" />
    </XmlPeek>
    <XmlPeek
      XmlContent="$(Modification)"
      Query="/Modification/FileName/text()">
      <Output TaskParameter="Result" PropertyName="FileName" />
    </XmlPeek>
    <Message Text="$(FolderName)$(FileName)" />
  </Target>
</Project>

Note: I'm not really experienced in MSBuild so any advice on how to parse the XML output in a more elegant way is highly appreciated.

Hint: <XmlPeek> task requires .NET 4.0 MSBuild.