I want to create a build number which looks like Major.minor.Date.LastChangeSetInTFS, the problem is how to get last changeset number from the TFS. Is there any property, or something??
-
This has already been answered, have a look at: http://stackoverflow.com/questions/545566/aligning-assembly-version-numbers-with-tfs-buildnumber – Burt Oct 27 '09 at 13:53
-
@Burt The linked question/answer is about the auto-generated TFS BuildNumber, which is entirely different than the changeset number. – makhdumi Oct 14 '15 at 22:22
4 Answers
OK finally I've found a solution. Here's a task that will provide you the latest changeset number and create a property to insert it in an Assembly info build number. The main problem was in the missing TfsLibraryLocation property (without it, it should be pointing to libraries in GAC, but it didn't)
<Target Name="GetVersionChangeSet">
<TfsVersion
TfsLibraryLocation="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies"
LocalPath="$(SolutionRoot)">
<Output TaskParameter="Changeset" PropertyName="ChangesetNumber"/>
</TfsVersion>
<Message Text="TFS ChangeSetNumber: $(ChangesetNumber)" />

- 43,764
- 28
- 129
- 177

- 1,015
- 1
- 14
- 24
-
3For VS2010, the TfsLibraryLocation has changed to "$(DevEnvDir)ReferenceAssemblies\v2.0". Also, $(SolutionRoot) doesn't exist naturally but $(SolutionDir) does. – Scott Stafford Mar 17 '11 at 20:32
-
1The TfsVersion task doesn't appear to work for this any longer using TFS 2010. I have posted an answer for TFS 2010 here:http://stackoverflow.com/questions/11748338/tf-exe-on-tfspreview/12923581 – Derek Evermore Oct 16 '12 at 21:29
According to a comment on this page you can use the command line
tf changeset /latest /i
but I can't verify that from home.

- 70,509
- 14
- 132
- 163
-
`tf changeset /latest /i` gets the right information, but how to put that into a property? – Mark Cooper Sep 24 '15 at 06:05
Sorry, I cannot comment on the latest answer.
The TfsVersion task in the form you provided will only give you the latest changeset number in the $(SolutionRoot)
.
If you have something newer in $(SolutionRoot)\subdir
, the provided solution will not work, as it will give you the latest from the $(SolutionRoot)
, not from $(SolutionRoot)\subdir
as you would have wanted.
I use the tf changeset /latest /i
and it works fine for me.

- 182
- 1
- 9
-
FYI... this will get the latest changeset in TFS regardless of what changeset you currently have in your local folder. – Brian Low Jul 18 '12 at 00:45
Check out following extension projects. You'll find about 5 different ways to solve your problem.
- MSBuild Extension Pack - actively maintained, this extension provides over 280 tasks
- MSBuild Community Tasks Project - not maintained since 2007, this set of ~90 tasks still has a few unique tasks, namely the flat-file-based Version task
- SDC Tasks Library - not maintained since Aug 2008, this extension have been absorbed into MSBuild Extension Pack. If there's something you can't find in MSBuild Extension Pack, check this one out, with its portfolio of 300+ tasks chances are, it may have what you need.

- 18,653
- 9
- 68
- 83