Skip to main content

.NET: Getting and Setting the Application Version Number

In the AssemblyInfo.cs file for each project, you have the opportunity to set the version number of the Assembly. A version number is designed by four number: major.minor.build.revision. The default is 1.0.* If left to this, third number (build) will be set to the number of days since January 1, 2000 local time. The fourth number (revision) will be set to the number of seconds since midnight local time. This is useful since it will always increment every time you build the assembly, unless you are working at 2 a.m. on the last Sunday in October in most places in the United States. However, in a production environment, you may want to control those numbers manually. In which case, you could set the version to something like 1.3.25.31. Note that .NET considers changes to the major or minor version to be significant changes, but changes to the build and revision are not. So if you have a reference to an Assembly in the Global Assembly Cache and the major or minor version changes, the new version is considered incompatible with the old version and the previous version will still be linked to. To retrieve the version number from the assembly in your code, you use can do this: String strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); To retrieve the version number from the assembly that is calling your assembly, you can use this: String strVersion = System.Reflection.Assembly.GetCallingAssembly().GetName().Version();

Comments

Popular posts from this blog