Having the Assembly version is great. This give us insights of wich version is running. Have the build time can also useful. Specially when we're troubleshooting our application and we're not sure of which version is running.
For instance besides having only the assembly version we can have the version + time of the build. Such as version 1.1.0 build at 2021-04-21 23:11:00.
Often in our Developer, DevOps or infrastructure life we find ourselves wondering:
Is this the right assembly?
Why my changes are not there? What happened?
WHich version is this? Is this the latest version?
Oh man, why is this not working? Oh my gosh. I hate this... hahhahaha
This happens especially when we don't have control over the deployment and it's published by a third-party professional.
By default, DotNet doesn't provide us that. Let's get started! > This works in .Net Core 3.1 and .NET 5.
To make this happen we're going to tell .NET compiler while building the code to also write in the assembly's SourceRevisionId tag the System.DateTime.Now or System.DateTime.UtcNow.
Adding Build Time to Our Assembly
Open your csprojfile and add the tag SourceRevisionId with the following content.
This works for Console App, Windows Forms, WPF and Web App. Xamarin. What about others? I have no clue. Leave a comment if you know.
To get the written date using C# create the method GetLinkerTime() as described next.