SlashPineTech.Forestry.Versioning 2.0.0-rc.1

This is a prerelease version of SlashPineTech.Forestry.Versioning.
dotnet add package SlashPineTech.Forestry.Versioning --version 2.0.0-rc.1
                    
NuGet\Install-Package SlashPineTech.Forestry.Versioning -Version 2.0.0-rc.1
                    
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="2.0.0-rc.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SlashPineTech.Forestry.Versioning" Version="2.0.0-rc.1" />
                    
Directory.Packages.props
<PackageReference Include="SlashPineTech.Forestry.Versioning" />
                    
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 SlashPineTech.Forestry.Versioning --version 2.0.0-rc.1
                    
#r "nuget: SlashPineTech.Forestry.Versioning, 2.0.0-rc.1"
                    
#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 SlashPineTech.Forestry.Versioning@2.0.0-rc.1
                    
#: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=SlashPineTech.Forestry.Versioning&version=2.0.0-rc.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SlashPineTech.Forestry.Versioning&version=2.0.0-rc.1&prerelease
                    
Install as a Cake Tool

MIT License

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 version metadata into an assembly for use when the application is running.

Usage

Excluding Source Revision from Version Number

As of .NET 8, the source revision is included in the informational version by default. You can disable this with the following in your .csproj:

<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>

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 AddVersionMetadata extension method to register a singleton instance of VersionMetadata with all the metadata that was compiled into the assembly in the prior step.

services.AddVersionMetadata(typeof(Startup).Assembly);

To map a /version endpoint that will return this information as JSON, add the following to Startup.Configure:

app.UseEndpoints(endpoints =>
{
    ...

    endpoints.MapVersion("/version").AllowAnonymous();
});

Wrapping up

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

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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
2.0.0-rc.1 209 8/6/2025
1.0.0 16,431 3/26/2022