Some instructions on how to automatically increment the build number of your Visual Studio project.
What was important to me was to automatically increment the build and version number of my executable files using Visual Studio.
Some important StackOverflow links helped me to achieve this:
To demonstrate the instructions contained in the StackOverflow links, first create a new Visual Studio project. For simplicity, choose a .NET console application:
Notice that a file called AssemblyInfo.cs is automatically created:
Modify the AssemblyInfo.cs file, so that the AssemblyVersion attribute ends with an asterisk.
Also comment out or remove the second of these lines, AssemblyFileVersion, so that we just have the following:
AssemblyInfo.cs
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Versioning")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Versioning")] [assembly: AssemblyCopyright("Copyright © 2018")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("2168d21a-54ac-4613-a701-1e468f46ee62")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyFileVersion("1.0.0.0")]
Then modify the main program so that we can inspect our current build version information:
Program.cs
using System; using System.Reflection; namespace Versioning { internal static class Program { private static void Main(string[] args) { var version = Assembly.GetExecutingAssembly().GetName().Version; var buildDate = new DateTime(2000, 1, 1) .AddDays(version.Build).AddSeconds(version.Revision * 2); var displayableVersion = $"{version} ({buildDate})"; Console.WriteLine("Current version (inc. build date) = " + displayableVersion); } } }
Giving the following output:
Notice that on selecting the properties > details tab of the program executable, the file version information is available here also: