Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to know the version of the program to add it to the form's name.

What I have tried:

Changing every new version this string:
C#
string version="4.8".

And use this string everywhere
Posted
Updated 6-Mar-17 5:04am

Not sure what you want to achieve, but you can check this: c# - How can I get the assembly file version - Stack Overflow[^]

More details at: AssemblyName.Version Property (System.Reflection)[^]
 
Share this answer
 
Comments
john1990_1 6-Mar-17 15:15pm    
i want the "publish version" that i change in project->properties manually.
Maciej Los 7-Mar-17 2:07am    
john1990_1 7-Mar-17 6:28am    
worked, i used this:


if (ApplicationDeployment.IsNetworkDeployed)
{
version = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(2);
}
Maciej Los 7-Mar-17 13:33pm    
Great!
Chears,
Maciej
john1990_1 7-Mar-17 15:34pm    
thx a lot :)
For any type of app:
C#
Assembly.GetExecutingAssembly().GetName().Version
For a WinForm app:
C#
Application.ProductVersion
Using GetExecutingAssembly for an assembly reference is not always an option. This a useful static helper class for projects where you need to reference the underlying assembly or assembly version:
C#
public static class CoreAssembly
{
    public static readonly Assembly Reference = typeof(CoreAssembly).Assembly;
    public static readonly Version Version = Reference.GetName().Version;
}
 
Share this answer
 
Comments
john1990_1 6-Mar-17 15:15pm    
i cant understand the third block of code, i want the "publish version" that i change in project->properties manually.
Graeme_Grant 6-Mar-17 22:52pm    
This is the version number from the AssemblyInfo.cs properties class. Did you try it?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900