Reputation: 53
The project is hosted on a tfs server and I need to access the build number which I assume is automatically generated when ever you build a project.
I need to retrieve that build number and display it on the web pages so that QAs and testing people know exactly which build they are working on.
I found how to create customize build numbers in the following link: http://msdn.microsoft.com/en-us/library/aa395241(v=vs.100).aspx
but it dose not solve my problem as I do not have access to the build definition file.
I am looking for some kind of post deployment task which can access the build number or may be generate one and probably write it down to a file, from where I can read it. I don't know if that makes any sense as this is my first time working on .Net
Upvotes: 2
Views: 3279
Reputation: 53
So this is how I ended up implementing it Thanks to John and mclaassen.
In my AssemblyInfo.cs, I made the following changes:
before:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
after:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
then I wrote a helper class which can access the AssemblyVersion number, with a get method.
public string GetVersion()
{
string version ;
version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
return version;
}
so when ever I call this method it gives me a string which is nothing but my version number.
Upvotes: 1
Reputation: 23434
You would do best to use the TFS Version activity from the TFS Community build tools. This tool automatically grabs the version number from the build name and can be easily configured to update the AssemblyInfo.* files after the get, and before the compile.
Of all the tools out there this is the best supported one. I find any of the others overly complicated. I have used this on hundreds of builds for many customers.
Upvotes: 0
Reputation: 5128
You could do something like this:
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
or alternatively if you have multiple assemblies then you can use
Assembly.GetAssembly(typeof(SomeObject))
where SomeObject
is declared in the assembly you want to get the version of.
Upvotes: 3