Increment version automatically, and get version number via code

Asked

Viewed 2,321 times

9

In the software in which I am working there are users, whose doubts should be met by observing the version number of the software.

Something like 10.0.1.1000 configured in project properties.

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

  • Aaah Miguelito =*

3 answers

11


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

[assembly: AssemblyVersion("1.1.*")

The build number (3rd digit) corresponds to the number of days passed since the beginning of the year 2000 and will be incremented daily, and the number of the Revision (4th digit) corresponds to' number of seconds passed since midnight of the current day.

You can find more information about these rules here. If you want to have more control over Assembly’s version, I recommend using a "build server" or integration server continues (e.g.: Teamcity).

To programmatically get the Assembly version, you have to use Reflection:

string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

5

For add-on only, you can also edit the attribute AssemblyVersion by the project configuration dialog box, in the project properties... the shortcut is usually ALT + ENTER, and then click on Assembly Information in the main guide:

inserir a descrição da imagem aqui

1

private string ObterVersaoApp()
{
    return string.Format("[versão {0}]", Assembly.GetExecutingAssembly().GetName().Version);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.