Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Version of my C# app?

I am working on desktop application. I have create a setup.

Ex. My Application. Version is 1.0.0.

I want to get the current version of my desktop application which is 1.0.0. I have tried by using Application.ProductVersion but it provides the version of my controls. (I am using DevExpress Control15.2.7, so it provides the current version as 15.2.7).

How can I get the current version of the installed application? I want to compare it to the installed version to provide a "New Version Available" functionality for my product.

like image 207
Nanji Mange Avatar asked Apr 01 '16 08:04

Nanji Mange


People also ask

How do I know my C version?

Type “gcc –version” in command prompt to check whether C compiler is installed in your machine. Type “g++ –version” in command prompt to check whether C++ compiler is installed in your machine.

How do I check my gcc version?

So if you ever need to check the version of the GCC C++ compiler that you have installed on your PC, you can do it through the command prompt by typing in the single line, g++ --version, and this will return the result.


2 Answers

The info you are looking for is in AssemblyInfo.cs.

To access the info written in there at runtime you can use the System.Reflection.Assembly.

Use System.Reflection.Assembly.GetExecutingAssembly() to get the assembly (that this line of code is in) or use System.Reflection.Assembly.GetEntryAssembly() to get the assembly your project started with (most likely this is your app).

In multi-project solutions this is something to keep in mind!

string version = Assembly.GetExecutingAssembly().GetName().Version.ToString() // returns 1.0.0.0 

Corresponding AssemblyInfo.cs:

AssemblyInfo.cs

Corresponding EXE-properties:

EXE properties

This may be important when working with InstallShield (see comments) !

like image 60
Felix D. Avatar answered Oct 04 '22 17:10

Felix D.


System.Reflection.Assembly executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); var fieVersionInfo = FileVersionInfo.GetVersionInfo(executingAssembly .Location); var version = fieVersionInfo.FileVersion; 
like image 22
Nitin Avatar answered Oct 04 '22 17:10

Nitin