LinkDotNet.BuildInformation 2.3.0

dotnet add package LinkDotNet.BuildInformation --version 2.3.0
                    
NuGet\Install-Package LinkDotNet.BuildInformation -Version 2.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LinkDotNet.BuildInformation" Version="2.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinkDotNet.BuildInformation" Version="2.3.0" />
                    
Directory.Packages.props
<PackageReference Include="LinkDotNet.BuildInformation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LinkDotNet.BuildInformation --version 2.3.0
                    
#r "nuget: LinkDotNet.BuildInformation, 2.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LinkDotNet.BuildInformation@2.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LinkDotNet.BuildInformation&version=2.3.0
                    
Install as a Cake Addin
#tool nuget:?package=LinkDotNet.BuildInformation&version=2.3.0
                    
Install as a Cake Tool

Incremental Build Information Generator

.NET Nuget GitHub tag

This project provides a C# source generator that embeds build information in a BuildInformation class at compile time. The values describe the build that produced the assembly; they are not read from the machine at runtime.

Features

  • Embeds build date (in UTC) in your code. Honors SOURCE_DATE_EPOCH for 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 assembly version, file version, informational version, name, company, and copyright
  • Embeds the target framework moniker in your code
  • Embeds the nullable-context setting, analysis level, and deterministic-build flag
  • Embeds the project directory when explicitly enabled (disabled by default to avoid exposing local paths)
  • Embeds the language and configured language version (like "C#" and "12.0")
  • Embeds whether the build uses Release optimization, plus the Roslyn compiler and .NET SDK runtime versions
  • Optionally embeds the direct and transitive dependencies (name and version)

The generator is an analyzer and adds no runtime dependency. The generated BuildInformation class is internal by default, in the global namespace, and its members are public.

Configuration

The NuGet package makes all needed MSBuild properties visible to the generator automatically, so setting the property is enough.

To put the generated class in the project's root namespace (useful when multiple projects reference each other), add this to your project file:

<PropertyGroup>
    <UseRootNamespaceForBuildInformation>true</UseRootNamespaceForBuildInformation>
</PropertyGroup>

With this option enabled, include the root namespace in your using directive.

The AllowProjectDirectoryBuildOutput property includes the project directory in the generated class. It is disabled by default because local paths may be sensitive.

<PropertyGroup>
    <AllowProjectDirectoryBuildOutput>true</AllowProjectDirectoryBuildOutput>
</PropertyGroup>

Dependencies

Set IncludeDependenciesInBuildInformation to embed the resolved direct and transitive dependencies (NuGet packages and project references) of the current target framework:

<PropertyGroup>
    <IncludeDependenciesInBuildInformation>true</IncludeDependenciesInBuildInformation>
</PropertyGroup>
foreach (var dependency in BuildInformation.DirectDependencies)
{
    Console.WriteLine($"{dependency.Name} {dependency.Version}");
}

foreach (var dependency in BuildInformation.TransitiveDependencies)
{
    Console.WriteLine($"{dependency.Name} {dependency.Version}");
}

// {"direct":[{"name":"Serilog.Sinks.Console","version":"6.0.0"}],"transitive":[{"name":"Serilog","version":"4.0.0"}]}
Console.WriteLine(BuildInformation.DependenciesJson);
How it works

When enabled, the package adds the project's project.assets.json (written by dotnet restore) as an AdditionalFiles item. The generator reads the entry for the current target framework: every resolved package or project is a dependency, and the ones declared in the project file are the direct ones; everything else is transitive. Versions are the resolved versions, not the ranges from the project file.

Everything is computed at compile time, so there is no runtime cost and DependenciesJson is a const. The generator step costs a few milliseconds per compilation (about 1 ms for ~50 packages and about 7 ms for a 770 KB assets file with 4 target frameworks), and in the IDE it only runs again when the assets file changes.

The feature is opt-in because the exact package versions are embedded in your assembly, where anyone can read them and look up known vulnerabilities. It also adds a string for every dependency to the binary. DependenciesJson is a lightweight list and not a standardized SBOM; use tools like CycloneDX or Microsoft.Sbom.Targets for CycloneDX or SPDX documents.

Reproducible builds

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 build

Usage

Install the NuGet package in an SDK-style C# project:

dotnet add package LinkDotNet.BuildInformation

Build the project, then use the generated class in your code. With the default global namespace, no namespace import is needed:

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($"Nullability: {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}");
Console.WriteLine($"Release build: {BuildInformation.IsReleaseBuild}");

The sample project shows all generated values and opts into the root namespace and project directory. It references the generator project directly for local development; package consumers only need the NuGet package above. Hover over the properties in an IDE to see their generated XML documentation.

An example output could look like this (values depend on the build environment):

Build at: 2026-10-31T20:59:26.0000000Z
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
Nullability: Enable
Deterministic build: True
Analysis level: 10.0
Project directory: /path/to/LinkDotNet.BuildInformation.Sample/
Language: C#
Language version: 14.0
Compiler version: 5.9.0.0
DotNet SDK version: .NET 10.0.14
Release build: False

The .NET SDK appends the commit SHA to AssemblyInformationalVersion when source revision information is available. To disable that behavior, set <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> in your project.

Contributing

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.

License

This project is licensed under the MIT License.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on LinkDotNet.BuildInformation:

Repository Stars
linkdotnet/Blog
A blog (engine) completely written in C# and Blazor. It aims to be a simple use and easy to extend platform. Blogposts are written in Markdown and are rendered to HTML. This gives all the flexibility needed to express yourself but also have an easy way of creating posts in the first place.
C9Glax/tranga
Monitor and download Manga automatically in a Docker-Container.
Version Downloads Last Updated
2.3.0 63 11/20/2026
2.2.0 1,855 10/4/2026
2.1.5 5,910 6/24/2026
2.1.4 523 5/16/2026
2.1.3 153 5/15/2026
2.1.2 3,817 12/9/2025
2.1.1 523 12/9/2025
2.1.0 1,404 12/8/2025
2.0.0 842 12/3/2025
1.3.0 11,913 10/11/2024
1.2.1 18,639 5/2/2024
1.2.0 2,343 4/25/2024
1.1.2 1,175 4/20/2024
1.1.1 289 4/19/2024
1.0.0 4,128 12/30/2023
0.4.2 6,177 8/29/2023
0.4.1 1,466 8/12/2023
0.4.0 1,282 6/15/2023
0.3.0 4,818 3/24/2023
0.1.0 1,489 3/24/2023