build time can be useful sometimes. For instance, in a web application, we can have the version and the date that was made 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 the 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... ahahhahaha_
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
SourceRevisionId tag the
Adding Build Time to Our Assembly
Add to the CSPROJ file the tag
SourceRevisionId with the following content.
This works for Console App , Windows Forms , WPF and Web App. Xamarin and others I have no clue about.
Leave a comment if you know.
To get the written date using C# create the method
GetLinkerTime() as described next.
Full Application - Sample Console Application