Python 3 script to update the build numbers in .NET source files. Ideal for part of a continuous integration / build system.
Update the build numbers in .NET source files. Ideal for part of a continuous integration / build system.
This Python 3 script allows you to update the build number in the version settings in C# .NET source files. It can be run from the command prompt or from within a build system and will set the build numbers in the AssemblyInfo.cs
or CommonAssemblyInfo.cs
files in a given directory and its subdirectories.
If you’re using an automated build / continuous integration (CI) system, you probably want to update the version numbers of the files being built as part of the build process.
One way to implement automatic versioning in your build system could be:
AssemblyInfo.cs
files (Company details, copyright, version specifications etc.) and place it in a new file called CommonAssemblyInfo.cs
in the root folder with the solution. Add this file to each project as a link, NOT a source file. Once you’ve done this, any changes to CommonAssemblyInfo.cs
will naturally appear in all of the modules.MSDN Article: Assembly Versioning - The Significance Of Each Of The Numbers In A Version says that the structure of the Windows version block is:
<major version><minor version><build number><revision>
There are two version numbers in .NET, AssemblyVersion and AssemblyFileVersion. The differences between them are explained at: MSDN Article: How to use Assembly Version and Assembly File Version.
Alternatively for APIs the SemVer2 standard is straightforward, logical and has helped at least one of my friends’ departments pass a development audit. It’s definitely worth considering.
From a Windows command line, if you want to set the versions in the files in the directory E:\Articles\Examples\Versioning
to 7434 this script can be run as:
python updateversions.py "E:\Articles\Examples\Versioning" 7434
Running:
python updateversions.py -h
will display the required and optional parameters for the script.
This script has no unit tests at the moment. A future version will probably include tests.
This project is licensed under the terms of the MIT license.
The original version of this script was published as part of my web site at:
https://softwarepragmatism.com/automatically-version-everything