Click here to Skip to main content
Click here to Skip to main content

Changing Version Number Dynamically

, 23 Aug 2012
Rate this:
Please Sign up or sign in to vote.
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")]
  • 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.

    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)

About the Author

Purushotham Agaraharam
Software Developer Congruent Info-Tech
India India
No Biography provided
Group type: Organisation

5 members


Comments and Discussions

 
GeneralMy vote of 5 PinmemberChristian Amado23-Aug-12 7:09 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 23 Aug 2012
Article Copyright 2012 by Purushotham Agaraharam
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid