Changing Version Number Dynamically





5.00/5 (3 votes)
Dynamic changing of version number using SolutionInfo.cs through out the application.
Introduction
Changing the assembly version and assembly file version in AssemblyInfo.cs.
Guidelines to be followed
- Step 1: List out common parameters and dynamically changing one from AssemblyInfo.cs which is present under properties.
- Step 2: Copy AssemblyInfo.cs and put it in root directory of Solution Explorer and rename it to SolutionInfo.cs.
- Step 3: Put the Constant Parameters in SolutionInfo.cs and remove the remaining parameters.
//SolutionInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsFormsCheckVersion")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
//AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("WindowsFormsCheckVersion")]
[assembly: AssemblyDescription("")]
[assembly: Guid("e2ff28a6-9772-4681-9778-d8e4bed68ce0")]
(This has to be done to all projects where ever you need to change version Number)We need to keep it in mind that we should remove the parameters that are placed in SolutionInfo.cs.
If you want to check that version has been changed at all places we can check it with DLL or we can get it through application code also.
Assembly executingAssembly;
AssemblyName executingAssemblyName;
Version executingAssemblyVersion;
executingAssembly = Assembly.GetEntryAssembly();
executingAssemblyName = executingAssembly.GetName();
executingAssemblyVersion = executingAssemblyName.Version;
string assemblyVersion = executingAssemblyVersion.ToString(4);
MessageBox.Show(assemblyVersion);
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
MessageBox.Show(path);
Point to remember
Make sure that parameters that are placed under solutionInfo.cs should be removed in all AssemblyInfo.cs.