

Automated date based versioning for ASP.NET Core assemblies using Azure DevOps
source link: https://www.tuicool.com/articles/hit/ueqQnij
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I needed automatic version numbering based on current date when web application is built. It was wish by some customers and in their projects it’s okay with it. As their code is covered with automated tests and other diagnostics I’m using Azure DevOps as build server and this is where I made automated date based versioning work.
Before religious wars about versioningI mention that this kind of versioning doesn’t expose absolute truth or best practices. It comes with possible consequences and obstacles and one shouldn’t apply it to every project possible. I just happened to have few situations where date based versioning makes sense and is safe to use.
I tried few Azure DevOps tasks by third-parties and I got things running like expeced with Manifest Versioning Build Tasks by Richard Fennell . It’s free to use, no hidden or additional expenses!
Adding and configuring versioning task
Installation was easy. I installed it to my Azure DevOps account through adding new task to build pipeline and then added .NET Core version step. Build pipeline for my demo application is here and the name of versioning task is “Version .NET Core assemblies”.
To get it work few additional steps are needed. Under build pipeline options I changed the format of version number like shown on the following screenshot.
For those who want to repeat my steps the number format string is here for copy-paste: $(Build.DefinitionName)_$(date:yyyy).$(date:MM).$(date:dd)$(Rev:.r) .
Next step is to conigure version number task.
These settings should be enough to get automatic versioning work. No need to change anything in project files.
Build output of versioning task
Here is the fragment of versioning task output when build happened. I made red rectangles around important parts of versioning task output.
As a first thing task detects current build number. This is built based on options I set before. Then regular expression (Version Filter) is applied to build number and as a result date based version number is extracted. This version number is automatically set to all projects I have in repository because I made no more specific rules.
Displaying version number in ASP.NET Core application
To display version number at footer of web page I use the following code in layout page.
< div class = "col-md-4 col-sm-4">
< p class = "powered" > Version: @ System.Reflection.Assembly.GetAssembly(GetType()).GetName().Version.ToString() </ p > </ div>
Here is how it looks on web page footer.
Wrapping up
With Azure DevOps service it’s possible to move versioning of release assemblies to build pipeline keeping source code and developers machines clean of additional ballast. With right tools it’s easy to play with version numbers and automate versioning in build server. This blog post wen through steps to take to enable date based versioning of .NET Core assemblies. I spent around 15 minutes to get things work with task mentioned above and I think it’s stong enough argument to blog about it.
Recommend
-
32
Reference Assemblies, what are they, why do I need that? Reference Assemblies are a special kind of assembly that’s passed to the compiler as a reference. They do not contain any implementation and are not valid for norma...
-
358
README.md Using Donut
-
8
Dienstag, 8. Dezember 202018:30 bis 20:30 MEZOnline-EventDieses Event ist vorbeiDetails
-
20
Lazy Loading Syncfusion Blazor Assemblies in a Blazor WebAssembly ApplicationThe Blazor platform provides support for
-
3
Member KevinRansom commented
-
8
Building Azure AD B2C custom policies part 2: Azure DevOps automated build and deployment Posted on: 06-03-2021...
-
13
Algorithms are providing a way to fairly select citizens’ assemblies The system picks candidates who represent the public...
-
3
In 2020, I left my desk at Amber Westerman Building Design to build my own home. It’s a 1208-sq.-ft. superinsulated, all-electric, net-zero
-
8
Concepts in phased assemblies 17 April 2021 Concepts in phased assembly: Contig: a contigu...
-
5
Abreak: evaluating de novo assemblies 07 July 2014 “Abreak” is a subcommand of htsbox, which is a little toy forked from...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK