This project provides a simple and easy-to-use C# source generator that embeds build information, such as the build time, platform, warning level, and configuration, directly into your code. By using the BuildInformation class, you can quickly access and display these details.
- Embeds build date (in UTC) in your code. Honors
SOURCE_DATE_EPOCHfor reproducible builds - Embeds platform (AnyCPU, x86, x64, ...) information in your code
- Embeds compiler warning level in your code
- Embeds build configuration (e.g., Debug, Release) in your code
- Embeds the assembly version and assembly file version in your code
- Embeds the assembly informational version (e.g.
1.2.3-beta+abc123) in your code. The .NET SDK appends the commit SHA automatically (disable via<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>) - Embeds the target framework moniker in your code
- Embeds the nullability analysis level in your code
- Embeds the deterministic build flag in your code
- Embeds the project path where the generator is running in your code
- Embeds the language and language version (like "C#" and "12.0")
The NuGet package makes all needed MSBuild properties visible to the generator automatically, so setting the property is enough.
By default the created class is internal and is not under any namespace. This can be changed by adding the following to your project file:
<PropertyGroup>
<UseRootNamespaceForBuildInformation>true</UseRootNamespaceForBuildInformation>
</PropertyGroup>This will use the root namespace of the project for the generated class. This is especially helpful if the generator is used in multiple projects, that might be visible to each other.
The AllowProjectDirectoryBuildOutput property is used to allow the generator to write the project directory into the generated class. This is disabled by default, as it might leak sensitive information.
<PropertyGroup>
<AllowProjectDirectoryBuildOutput>true</AllowProjectDirectoryBuildOutput>
</PropertyGroup>If the SOURCE_DATE_EPOCH environment variable (or MSBuild property) is set to a Unix timestamp, it is used for BuildAt instead of the current time. This makes the generated code identical across builds of the same commit:
SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) dotnet buildTo use the BuildInformation class in your project, add the NuGet package:
dotnet add package LinkDotNet.BuildInformation
Here is some code how to use the class:
using System;
Console.WriteLine($"Build at: {BuildInformation.BuildAt}");
Console.WriteLine($"Platform: {BuildInformation.Platform}");
Console.WriteLine($"Warning level: {BuildInformation.WarningLevel}");
Console.WriteLine($"Configuration: {BuildInformation.Configuration}");
Console.WriteLine($"Assembly version: {BuildInformation.AssemblyVersion}");
Console.WriteLine($"Assembly file version: {BuildInformation.AssemblyFileVersion}");
Console.WriteLine($"Assembly informational version: {BuildInformation.AssemblyInformationalVersion}");
Console.WriteLine($"Assembly name: {BuildInformation.AssemblyName}");
Console.WriteLine($"Assembly copyright: {BuildInformation.AssemblyCopyright}");
Console.WriteLine($"Assembly company: {BuildInformation.AssemblyCompany}");
Console.WriteLine($"Target framework moniker: {BuildInformation.TargetFrameworkMoniker}");
Console.WriteLine($"Analysis level: {BuildInformation.Nullability}");
Console.WriteLine($"Deterministic build: {BuildInformation.Deterministic}");
Console.WriteLine($"Analysis level: {BuildInformation.AnalysisLevel}");
Console.WriteLine($"Project directory: {BuildInformation.ProjectDirectory}");
Console.WriteLine($"Language: {BuildInformation.Language}");
Console.WriteLine($"Language version: {BuildInformation.LanguageVersion}");
Console.WriteLine($"Compiler version: {BuildInformation.CompilerVersion}");
Console.WriteLine($"DotNet SDK version: {BuildInformation.DotNetSdkVersion}");You can also hover over the properties to get the currently held value (xmldoc support). An example output could look like this:
Build at: 15.05.2026 08:22:23
Platform: AnyCpu
Warning level: 10
Configuration: Debug
Assembly version: 1.0
Assembly file version: 1.2
Assembly informational version: 1.0.0+da778dfd0f233100b6cbaf0689f8f8d35f60b975
Assembly name: LinkDotNet.BuildInformation.Sample
Assembly copyright: LinkDotNet 2025
Assembly company: LinkDotNet
Target framework moniker: net10.0
Analysis level: Enable
Deterministic build: True
Analysis level: 10.0
Project directory: /Users/stevengiesel/repos/BuildInformation/LinkDotNet.BuildInformation.Sample/
Language: C#
Language version: 14.0
Compiler version: 5.7.0.0
DotNet SDK version: .NET 11.0.0-preview.3.26207.106
If you would like to contribute to the project, please submit a pull request or open an issue on the project's GitHub page. We welcome any feedback, bug reports, or feature requests.
This project is licensed under the MIT License.