Blun.Build.Tasks.BuildTimeStamp
0.1.2
See the version list below for details.
dotnet add package Blun.Build.Tasks.BuildTimeStamp --version 0.1.2
NuGet\Install-Package Blun.Build.Tasks.BuildTimeStamp -Version 0.1.2
<PackageReference Include="Blun.Build.Tasks.BuildTimeStamp" Version="0.1.2" />
<PackageVersion Include="Blun.Build.Tasks.BuildTimeStamp" Version="0.1.2" />
<PackageReference Include="Blun.Build.Tasks.BuildTimeStamp" />
paket add Blun.Build.Tasks.BuildTimeStamp --version 0.1.2
#r "nuget: Blun.Build.Tasks.BuildTimeStamp, 0.1.2"
#:package Blun.Build.Tasks.BuildTimeStamp@0.1.2
#addin nuget:?package=Blun.Build.Tasks.BuildTimeStamp&version=0.1.2
#tool nuget:?package=Blun.Build.Tasks.BuildTimeStamp&version=0.1.2
Blun.Build.Tasks.BuildTimeStamp
📝 Introduction
A small MSBuild Task that inserts a build timestamp into assembly metadata during build. This allows applications to read the build time at runtime.
The package adds an assembly-level System.Reflection.AssemblyMetadataAttribute with key BuildTimeStamp_UTC and an ISO 8601 UTC timestamp value. The package also ships MSBuild .props/.targets to integrate automatically when the NuGet package is referenced.
➕ Features
- Writes
AssemblyMetadata("BuildTimeStamp_UTC", "<ISO8601 UTC timestamp>")at build time. - Timestamp is generated during packing/build so it reflects the build time of the produced artifact.
- Provides a small runtime helper
BuildTimeStampInformationto read the timestamp easily.
🚀 Quick Start / Installation
Install the NuGet package into your project (the package is published as Blun.Build.Tasks.BuildTimeStamp). For example with the .NET CLI:
# using the .NET CLI
dotnet add package Blun.Build.Tasks.BuildTimeStamp
When the package is installed the included build/Blun.Build.Tasks.BuildTimeStamp.props and build/Blun.Build.Tasks.BuildTimeStamp.targets are imported automatically by the SDK-style project system.
⚙️ How it works
The project includes an <AssemblyAttribute> item that adds the assembly metadata key/value pair:
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>BuildTimeStamp_UTC</_Parameter1>
<_Parameter2>$([System.DateTimeOffset]::UtcNow.ToString('o'))</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
This results in an assembly attribute similar to:
[assembly: System.Reflection.AssemblyMetadata("BuildTimeStamp_UTC", "2025-01-01T12:34:56.789Z")]
✅ Usage at runtime
The repository provides the BuildTimeStampInformation helper (see the example/TestBuildApp) which looks up the assembly metadata and exposes the timestamp in a convenient format.
Example using the helper class:
var buildTimeStampInformation = new BuildTimeStampInformation();
Console.WriteLine($"BuildTime: {buildTimeStampInformation.BuildTimeStampUtcIso8601String}");
If you prefer to read the metadata directly, you can use reflection:
using System.Reflection;
using System.Linq;
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
var metadataAttributes = assembly.GetCustomAttributes<System.Reflection.AssemblyMetadataAttribute>();
var buildTime = metadataAttributes.FirstOrDefault(a => a.Key == "BuildTimeStamp_UTC")?.Value;
Console.WriteLine(buildTime ?? "(no build timestamp found)");
Notes:
- The timestamp is stored in ISO 8601 format (UTC) and can be parsed with
DateTimeOffset.ParseorDateTimeOffset.TryParse. - When building packages or artifacts, ensure the packaging/build step runs in the environment and configuration that should stamp the artifact.
🗿 Example project
💡 The example/TestBuildApp demonstrates reading the timestamp via BuildTimeStampInformation and writing it to the console.
🎁 Contributing
Contributions are welcome. Suggested ways to help:
- Improve documentation or add examples
- Add tests or fix failing tests
- Report issues or request features via the repository issue tracker
Please follow repository coding conventions and add tests for any behavior changes.
💰 License
See the LICENSE file in the repository root for license terms.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
First release, provide a MSBuild Task how adds a System.Reflection.AssemblyMetadataAttribute with the BuildTimeStamp.
To read them do:
var buildTimeStampInformation = new BuildTimeStampInformation();
System.Console.WriteLine($"BuildTime: {buildTimeStampInformation.BuildTimeStampUtcIso8601String}");