SlashPineTech.Forestry.Versioning 1.0.0

dotnet add package SlashPineTech.Forestry.Versioning --version 1.0.0                
NuGet\Install-Package SlashPineTech.Forestry.Versioning -Version 1.0.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="SlashPineTech.Forestry.Versioning" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SlashPineTech.Forestry.Versioning --version 1.0.0                
#r "nuget: SlashPineTech.Forestry.Versioning, 1.0.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.
// Install SlashPineTech.Forestry.Versioning as a Cake Addin
#addin nuget:?package=SlashPineTech.Forestry.Versioning&version=1.0.0

// Install SlashPineTech.Forestry.Versioning as a Cake Tool
#tool nuget:?package=SlashPineTech.Forestry.Versioning&version=1.0.0                

Forestry .NET -- Versioning

Forestry .NET is a set of open-source libraries for building modern web applications using ASP.NET Core.

This versioning package adds support for embedding build-time metadata into an assembly for use when the application is running.

Usage

Configuring your .csproj

Add the following <ItemGroup> to the .csproj for your main assembly.

<ItemGroup>
  <AssemblyAttribute Include="SlashPineTech.Forestry.Versioning.BuildDateAttribute">
    <_Parameter1>$([System.DateTime]::UtcNow.ToString("o"))</_Parameter1>
  </AssemblyAttribute>
  <AssemblyAttribute Include="SlashPineTech.Forestry.Versioning.BuildNumberAttribute" Condition="$(BuildNumber) != ''">
    <_Parameter1>$(BuildNumber)</_Parameter1>
  </AssemblyAttribute>
  <AssemblyAttribute Include="SlashPineTech.Forestry.Versioning.SourceBranchAttribute" Condition="$(Branch) != ''">
    <_Parameter1>$(Branch)</_Parameter1>
  </AssemblyAttribute>
  <AssemblyAttribute Include="SlashPineTech.Forestry.Versioning.SourceCommitAttribute" Condition="$(Commit) != ''">
    <_Parameter1>$(Commit)</_Parameter1>
  </AssemblyAttribute>
</ItemGroup>

Configuring your CI

Next, configure your CI to pass metadata to dotnet build (or package).

Note: All CI platforms expose environment variables containing the metadata you need. The example below is using GitHub's environment variables. Consult the documentation for your CI platform for the specific variables to use.

dotnet build -p:BuildNumber=$GITHUB_RUN_NUMBER -p:Branch=$GITHUB_REF -p:Commit=$GITHUB_SHA

Startup

Use the BuildMetadataProvider to register a singleton instance of BuildMetadata with all of the metadata that was compiled into the assembly in the prior step.

services.AddSingleton(_ => new BuildMetadataProvider(typeof(Startup).Assembly).Provide());

Wrapping up

Now you can inject BuildMetadata anywhere you need to access this information, such as a /version endpoint that will return this as JSON or an MVC or Razor Page that will display this to administrators.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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
1.0.0 12,990 3/26/2022