I would like to programmaticly get a stored major version number for a C# project in both Debug and Release builds.
Where could I store this version number and how do i access it?
I would like to programmaticly get a stored major version number for a C# project in both Debug and Release builds.
Where could I store this version number and how do i access it?
Go to Project Properties | Application | Assembly Information.
You can access the version via Assembly.GetExecutingAssembly().GetName().Version
The version number is typically defined in the AssemblyInfo.cs file (located in the Properties folder). You can get the version number programmatically like this:
Console.WriteLine(Assembly.GetExecutingAssembly().GetName().Version.ToString());
Or, if you want to access the different parts:
Version version = Assembly.GetExecutingAssembly().GetName().Version;
Console.WriteLine("Major={0}, Minor={1}", version.Major, version.Minor);
See the Version
class documentation for more details.
I guess it depends on what you mean by store it, but you should look at:
ApplicationDeployment.CurrentDeployment.CurrentVersion
Edit: Actually this is for getting your deployed version. It might not be what you need.
to get your assembly version programmatically.
Assembly.GetExecutingAssembly().GetName().Version
Here is how to get the file version
System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)