I currently have an app displaying the build number in its title window. That\'s well and good except it means nothing to most of the users, who want to know if they have t
I needed a universal solution that worked with a NETStandard project on any platform (iOS, Android, and Windows.) To accomplish this, I decided to automatically generate a CS file via a PowerShell script. Here is the PowerShell script:
param($outputFile="BuildDate.cs")
$buildDate = Get-Date -date (Get-Date).ToUniversalTime() -Format o
$class =
"using System;
using System.Globalization;
namespace MyNamespace
{
public static class BuildDate
{
public const string BuildDateString = `"$buildDate`";
public static readonly DateTime BuildDateUtc = DateTime.Parse(BuildDateString, null, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
}
}"
Set-Content -Path $outputFile -Value $class
Save the PowerScript file as GenBuildDate.ps1 and add it your project. Finally, add the following line to your Pre-Build event:
powershell -File $(ProjectDir)GenBuildDate.ps1 -outputFile $(ProjectDir)BuildDate.cs
Make sure BuildDate.cs is included in your project. Works like a champ on any OS!