Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add the build number into the assembly so that I can display it along with other information. Can someone guide me do the same.
Posted
Comments
RBhar 6-Mar-12 11:30am    
My CC Tray shows the Last build date as 1.0.27.8876.
I wanted the same revision number i.e 8876. Will[assembly:AssemblyVersion("1.0.0.*")] do the job?

You can specify your complete version structure using the assembly-level attribute System.Reflection.AssemblyVersionAttribute, please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx[^].

Usually you have this attribute auto-generated when you create any project from template in your file "AssemblyInfo.cs". Here is how it looks:
C#
using System.Reflection;

//...

[assembly: AssemblyVersion("1.32.12.11")]
// build number here is 12


You extract this structure using Reflection from any assembly. If you need an assembly of your application, you usually need an entry assembly, the one loaded first, having an entry point and referencing all other assemblies and executable module. To get it, use System.Reflection.Assembly.GetEntryAssembly(), but you can get this version information from any assembly you need. Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^].

In your code, you need to get the version attribute using System.Reflection.Assembly.GetCustomAttributes(System.Type, bool), please see:
http://msdn.microsoft.com/en-us/library/88d17d13.aspx[^].

For example:
C#
System.Reflection.AssemblyVersionAttribute GetAssemblyVersion(System.Reflection.Assembly assembly) {
    object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyVersionAttribute), false);
    if (attribute == null) return null;
    if (attrubutes.Length < 1) return null; //assembly is not versioned
    System.Reflection.AssemblyVersionAttribute attrubute = (System.Reflection.AssemblyVersionAttribute)attributes[0];
    return new System.Reflection.AssemblyVersionAttribute(attribute.Version);
} //GetAssemblyVersion


If this method returns null, it indicated that the assembly is not given a version. If this is not null, use the value in your display or elsewhere.

—SA
 
Share this answer
 
v2
Comments
[no name] 5-Mar-12 16:29pm    
5 as usual. So many details :-)
Sergey Alexandrovich Kryukov 5-Mar-12 17:01pm    
Thank you very much, Collin.
As much detail as needed to solve the problem in full, no more, no less.
--SA
Hi,
Check this[^].
Add this line into existing AssemblyInfo.cs file or into new one empty cs file:
C#
[assembly: AssemblyVersion("1.0.1.1")]


Or you can use
C#
[assembly: AssemblyVersion("1.0.*")]
to auto increment values on each build...

The version number has four parts, as follows:
<major version>.<minor version>.<build number>.<revision>


For more details also read this[^] and this[^]...
 
Share this answer
 
Libraries contain an AssemblyInfo.cs with in the Properties folder.

Towards the bottom of the file you will see this->

C#
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")]


Set the number as you see fit or adjust as the file says to auto incriment. There are numerous other things you can do as well.

Here is an article that has a decent add in for more complex scenerios.

Versioning Controlled Build[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900