Increment version automatically, and get version number via code

9

In the software I'm working on, there are users whose doubts should be answered by looking at the software version number.

Something of type 10.0.1.1000 configured in the project properties.

I would like to know how to increment the version number automatically in a Visual Studio project, to make it easier to build, and how to get that version number via code, so I can display it to the user.

    
asked by anonymous 29.01.2014 / 19:39

3 answers

11

You can use an asterisk to "ask" Visual Studio to auto-increment the version of the assembly

[assembly: AssemblyVersion("1.1.*")
The build number is the number of days passed since the beginning of the year 2000 and will be incremented daily, and the revision number (4th digit) is the number of seconds passed since midnight on current day.

You can find more information about these rules here . If you want to have more control over the assembly version, I recommend using a build server or continuous integration server (eg TeamCity / a>).

To get the assembly version programmatically, you have to use reflection:

string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
    
29.01.2014 / 19:45
5

Just to complement, you can also edit the AssemblyVersion attribute by the project configuration dialog box in the project properties ... the shortcut is usually ALT + ENTER , and then click Assembly Information on the main tab :

    
29.01.2014 / 19:59
1
private string ObterVersaoApp()
{
    return string.Format("[versão {0}]", Assembly.GetExecutingAssembly().GetName().Version);
}
    
31.01.2014 / 17:12