Hi,
I'm AssemblyMetadata by Benjamin Abt. I'm a small sample how to use Source Code Generators with .NET. In this case, this example just adds the local timestamp on build into a static class. You can use it to show your users when your application was built.
NuGet |
---|
<PackageReference Include="AssemblyMetadata"
Version="VERSIONHERE"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
Right now, only one sub class is offered.
The build time is provided as ISO 8601 string.
string timeIso8601 = AssemblyMetadataInfo.BuildInfo.BuildTimestamp;
You can use the format "o" to parse the string into DateTimeOffset.
DateTimeOffset buildOn = DateTimeOffset.ParseExact(AssemblyMetadataInfo.BuildInfo.BuildTimestamp, "o", null);
Also, the Source Code Generator adds the the build time as digits, so you can just concat the values instead to parse the string.
int day = AssemblyMetadataInfo.BuildInfo.BuildTimeDay;
int month = AssemblyMetadataInfo.BuildInfo.BuildTimeMonth;
int hour = AssemblyMetadataInfo.BuildInfo.BuildTimeYear;
Have fun!
Please donate - if possible - to necessary institutions of your choice such as child cancer aid, children's hospices etc. Thanks!