Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.96 KB

README-NuGet.md

File metadata and controls

56 lines (37 loc) · 1.96 KB

This project simplifies the process of adding build information to your .NET projects. It uses a source generator to embed details like build time, commit ID and branch directly into your code.

By default, the values are faked in debug mode. This can be changed in the [BuildInformation] attribute with the FakeIfDebug property.

Usage

Create a new partial class in your project and add the [BuildInformation] (from the Pekspro.BuildInformationGenerator namespace) attribute and define which information you want. For example:

[BuildInformation(AddBuildTime = true, AddGitCommitId = true)]
partial class MyBuildInformation
{

}

Constants will automatically be added to this class that you can use like this:

Console.WriteLine($"Build time: {MyBuildInformation.BuildTime}");
Console.WriteLine($"Commit id: {MyBuildInformation.Git.CommitId}");

Installation

Add the package to your application with:

dotnet add package Pekspro.BuildInformationGenerator

This adds a <PackageReference> to your project. It's recommended that you also add the attributes PrivateAssets and ExcludeAssets like below to exclude the source generator to your final assembly:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
      <PackageReference Include="Pekspro.BuildInformationGenerator" Version="0.2.0" 
        PrivateAssets="all" ExcludeAssets="runtime" />
  </ItemGroup>

</Project>

Setting PrivateAssets="all" means any projects referencing this one won't get a reference to the Pekspro.BuildInformationGenerator package.

Setting ExcludeAssets="runtime" ensures the Pekspro.BuildInformationGenerator.Attributes.dll file is not copied to your build output (it is not required at runtime).

Links

You can find more information and can report issues on GitHub.