How to Manage Version of Software Using C#.net In Windows application

How to check or mange the software or assembly version of .NET 8 windows app or .NET framework windows application or class library version.
In today's article I will show you a simple tutorial with an example that how you can automatically manage version of software or app in .NET 8 Windows App or .NET framework in windows application using c#.net. So, for this tutorial first we will create a new .NET 8 windows app with c#.net and add a form in it. After adding a form add a label control in it. In this label control we will display the version of the software.

Form in windows application
After this create the form load event. In this event we will write the code to generate the version of the application and assign it to the label control to display. This will auto change one you any change in the application. 
 using System.Globalization;
using System.Reflection;
using System;

namespace TestWinApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Version v = Assembly.GetExecutingAssembly().GetName().Version;
            string version = string.Format(CultureInfo.InvariantCulture, @"version:{0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision);
            lblVersion.Text = version;
        }
    }
} 
Here we are checking the version of the application and by using Assembly.GetExecutingAssembly().GetName().Version. This will help us to get the various detail like Major version number, Minor version no, Build no and Revision number of the application. After that used String.Format to concatenate or combine the various value to form the version of the windows app. In last to display the value i have assign the string value to label control. Now let's run the code to check the output. 

Verson Win App .Net 8

In above image you can see the first version of the application. After this code whenever you make the change, an assembly will change the version of software will also change and you will be able to get the release version of the application.

Post a Comment