Click here to Skip to main content
15,887,214 members
Articles / Programming Languages / C#
Tip/Trick

Changing Version Number Dynamically

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
23 Aug 2012CPOL1 min read 18.6K   7   1
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.
  • C#
    //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")]
  • Step 4: Remove the parameters that are mentioned in SolutionInfo.cs.
  • Step 5: Create a new folder under Solution Explorer, name it to SolutionItem, and add the SolutionInfo.cs file to this folder.
  • Step 6: Now Right click on Project > Add >Existing Item >select the solutionInfo.cs file, and choose Add Link File.
  • (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.

    C#
    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.

License

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


Written By
Software Developer (Senior) @ CSC
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
This is a Organisation

8 members

Comments and Discussions

 
GeneralMy vote of 5 Pin
Christian Amado23-Aug-12 7:09
professionalChristian Amado23-Aug-12 7:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.