开发者

How do I insert the latest TFS changeset number into an aspx page?

开发者 https://www.devze.com 2023-01-26 06:53 出处:网络
When we were using SVN, we\'d always print at the footer of our pages开发者_如何学C: \"Revision XXXX\". I\'ve been looking, but I can\'t figure out how to do the same thing with TFS. Can anyone offer

When we were using SVN, we'd always print at the footer of our pages开发者_如何学C: "Revision XXXX". I've been looking, but I can't figure out how to do the same thing with TFS. Can anyone offer some pointers?

In case this matters: we're using ASP.NET MVC. I'm guessing it doesn't matter, however.


You can use the default version system for assemblies to track revisions number without adding anything in TFS.

If you use the Major.Minor.* format in your AssemblyInfo's AssemblyVersion attribute (e.g. [assembly: AssemblyVersion("1.0.*")]) it will generate a version according to the following format:

Major.Minor.Build.Revision

where

  • Major = Your value
  • Minor = Your value
  • Build = Number of days since 2000/01/01
  • Revision = (Number of seconds since midnight on the day specified in Build) / 2

This will give you an always increasing number which gives you precise information on build date and time.

To use these values in your code, you can simply recover the version using Assembly.GetExecutingAssembly().GetName().Version.


You can update version number of projects in AssemblyInfo.cs using assembly versioning tools/techniques like this. Version number of an assembly can be updated based on TFS changeset number. Version number then can be displayed in application.


At least when it was released, TFS didn't allow symbol replacement in files which is what I think you're after. I'm not sure if that has changed in more recent versions.


Changeset != Version

That being said, you can add a setting in web.config that holds the version number, and display that on the page. The version number can be updated as part of the build process, but it will not correlate to a changeset.

I should probably add that this can become a circular problem. If you get the latest changeset number for a project, then add that to the config (as named above), then checkin, you are no longer displaying the latest changeset. Adding 1 to the latest changeset is not a guarantee either, because something can be checked in while you are updating the files.


We ended up using a MsBuild task that searches for a particular string and replaces with the appropriate value (not necessarily the revision number).

The task runs as part of our build templates and puts the revision number in all the files that have the token present.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号