Whenever we create a project in visual studio, a file named AssemblyInfo is created by itself which contains the attributes used to define the version of assembly during compilation.
Versioning an assembly helps to identify deployed assemblies and helps in troubleshooting as well.
Assembly version consist of four blocks
- Major Version
- Minor Version
- Build Number
- Revision
Major Version is used for manually incrementing the version for major releases.
Minor Version is incremented for minor releases.
Build Number is incremented automatically as part of every build.
Revision Is incremented for patches and hotfixes to build release into production environment. It is set to zero for first release of any major or minor version.
We can find the version of an assemble using C# or VB code in .Net.
We can find version of executing assembly (Current assembly) or load any other assembly from any location to find its version.
Here is the code sample for finding assembly version of executing assembly
C#
Version assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
VB
Dim assemblyVersion As Version = Assembly.GetExecutingAssembly().GetName().Version
Here is the code for finding assembly version for other .Net assemblies
C#
Version assemblyVersion = Assembly.LoadFile(@"Your Assembly Path").GetName().Version;
VB
Dim assemblyVersion As Version = Assembly.LoadFile("Your Assembly Path ").GetName().Version
In above code we are using Assembly class methods to find assembly version. Assembly class resides in System.Reflection namespace.
0 Comment(s)