Get list of files from tfs changeset

后端 未结 2 1315
孤城傲影
孤城傲影 2021-01-25 13:24

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 b

相关标签:
2条回答
  • 2021-01-25 13:39

    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.

    0 讨论(0)
  • 2021-01-25 13:48

    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)

    0 讨论(0)
提交回复
热议问题