Pekspro.BuildInformationGenerator
0.0.1-preview01
See the version list below for details.
dotnet add package Pekspro.BuildInformationGenerator --version 0.0.1-preview01
NuGet\Install-Package Pekspro.BuildInformationGenerator -Version 0.0.1-preview01
<PackageReference Include="Pekspro.BuildInformationGenerator" Version="0.0.1-preview01" />
paket add Pekspro.BuildInformationGenerator --version 0.0.1-preview01
#r "nuget: Pekspro.BuildInformationGenerator, 0.0.1-preview01"
// Install Pekspro.BuildInformationGenerator as a Cake Addin
#addin nuget:?package=Pekspro.BuildInformationGenerator&version=0.0.1-preview01&prerelease
// Install Pekspro.BuildInformationGenerator as a Cake Tool
#tool nuget:?package=Pekspro.BuildInformationGenerator&version=0.0.1-preview01&prerelease
Pekspro.BuildInformationGenerator
A Source Generator package that generates build information constants, like build time, commit id, branch etc.
Installation
This source generator requires the .NET 7 SDK. You can target earlier frameworks like .NET Core 3.1 etc, but the SDK must be at least 7.0.100
Add the package to your application with:
dotnet add package Pekspro.BuildInformationGenerator
This adds a <PackageReference>
to your project. You can additionally mark the package as PrivateAssets="all"
and ExcludeAssets="runtime"
.
Setting
PrivateAssets="all"
means any projects referencing this one won't get a reference to the Pekspro.BuildInformationGenerator package. SettingExcludeAssets="runtime"
ensures the Pekspro.BuildInformationGenerator.Attributes.dll file is not copied to your build output (it is not required at runtime).
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<PackageReference Include="Pekspro.BuildInformationGenerator" Version="0.0.1"
PrivateAssets="all" ExcludeAssets="runtime" />
</Project>
Usage
Create a new partial class in your project and add the [BuildInformation]
(from the Pekspro.BuildInformationGenerator
namespace) attribute to it.
For example:
[BuildInformation]
partial class MyBuildInformation
{
}
This will generate a class called MyBuildInformation
(by default), which contains a number of constants. For example:
static partial class MyBuildInformation
{
/// <summary>
/// Build time: 2024-06-09 13:12:59
/// </summary>
public static readonly global::System.DateTime BuildTime = new global::System.DateTime(638535355790224470L, global::System.DateTimeKind.Utc);
/// <summary>
/// The commit id in Git at the time of build: 712f143d13df1dcffad122a4184cb19b0c5424f3
/// </summary>
public const string GitCommitId = "712f143d13df1dcffad122a4184cb19b0c5424f3";
/// <summary>
/// The short commit id in Git at the time of build: 712f143
/// </summary>
public const string GitShortCommitId = "712f143";
}
You can also specify which properties to include in the generated class. For example:
[BuildInformation(Branch = true)]
partial class MyBuildInformation
{
}
This will add the Branch
property to the generated class:
/// <summary>
/// Git branch: master
/// </summary>
public const string GitBranch = "master";
Configuration
The [BuildInformation]
attribute has a number of properties you can set to control the generated class:
IncludeBuildTime
(default:true
): Include the build time.IncludeLocalBuildTime
(default:false
): Include the local build time.IncludeOSVersion
(default:false
): Include the OS version of the machine where the build happens.IncludeGitCommitId
(default:true
): Include the commit id.IncludeGitBranch
(default:false
): Include the branch name.IncludeDotNetSdkVersion
(default:false
): Include the .NET SDK version.IncludeWorkloadMaui
(default:false
): Include the workload for .NET MAUI.IncludeWorkloadWasmTools
(default:false
): Include the workload for WebAssembly tools.
If everything is set to true, the generated class will look like this:
static partial class BuildInfoAll
{
/// <summary>
/// Build time: 2024-06-09 14:05:48
/// </summary>
public static readonly global::System.DateTime BuildTime = new global::System.DateTime(638535387484914951L, global::System.DateTimeKind.Utc);
/// <summary>
/// Build time: 2024-06-09 16:05:48 (+02:00))
/// </summary>
public static readonly global::System.DateTimeOffset LocalBuildTime = new global::System.DateTimeOffset(638535459484914951L, new global::System.TimeSpan(72000000000));
/// <summary>
/// OS version of the building machine: Microsoft Windows NT 10.0.22631.0
/// </summary>
public const string OSVersion = "Microsoft Windows NT 10.0.22631.0";
/// <summary>
/// The commit id in Git at the time of build: 712f143d13df1dcffad122a4184cb19b0c5424f3
/// </summary>
public const string GitCommitId = "712f143d13df1dcffad122a4184cb19b0c5424f3";
/// <summary>
/// The short commit id in Git at the time of build: 712f143
/// </summary>
public const string GitShortCommitId = "712f143";
/// <summary>
/// Git branch: master
/// </summary>
public const string GitBranch = "master";
/// <summary>
/// .NET SDK version: 8.0.300
/// </summary>
public const string DotNetSdkVersion = "8.0.300";
/// <summary>
/// Workload MAUI version: 8.0.21/8.0.100
/// </summary>
public const string WorkloadMauiVersion = "8.0.21/8.0.100";
/// <summary>
/// Workload wasm-tools version: 8.0.5/8.0.100
/// </summary>
public const string WorkloadWasmToolsVersion = "8.0.5/8.0.100";
/// <summary>
/// Workload Aspire version: 8.0.0/8.0.100
/// </summary>
public const string WorkloadAspireVersion = "8.0.0/8.0.100";
}
Performance
You can also specify if you want to have faked values (to increase build time) with these settings:
FakeIfDebug
(default:true
): Fake values ifDEBUG
is defined.FakeIfRelease
(default:false
): Fake values ifRELEASE
is defined.
Credits
This project is hugely inspired by the NetEscapades.EnumGenerators project.
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. |
.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 | net451 is compatible. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. 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. |
-
.NETStandard 2.0
- 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.
Version | Downloads | Last updated |
---|---|---|
0.2.0 | 92 | 6/22/2024 |
0.2.0-preview02 | 57 | 6/22/2024 |
0.2.0-preview01 | 51 | 6/22/2024 |
0.1.0 | 88 | 6/18/2024 |
0.0.1-preview10 | 71 | 6/18/2024 |
0.0.1-preview09 | 75 | 6/16/2024 |
0.0.1-preview08 | 67 | 6/16/2024 |
0.0.1-preview07 | 67 | 6/15/2024 |
0.0.1-preview06 | 68 | 6/15/2024 |
0.0.1-preview05 | 71 | 6/15/2024 |
0.0.1-preview04 | 65 | 6/14/2024 |
0.0.1-preview03 | 79 | 6/11/2024 |
0.0.1-preview02 | 74 | 6/11/2024 |
0.0.1-preview01 | 80 | 6/10/2024 |