SlashPineTech.Forestry.Versioning
2.0.0-rc.1
dotnet add package SlashPineTech.Forestry.Versioning --version 2.0.0-rc.1
NuGet\Install-Package SlashPineTech.Forestry.Versioning -Version 2.0.0-rc.1
<PackageReference Include="SlashPineTech.Forestry.Versioning" Version="2.0.0-rc.1" />
<PackageVersion Include="SlashPineTech.Forestry.Versioning" Version="2.0.0-rc.1" />
<PackageReference Include="SlashPineTech.Forestry.Versioning" />
paket add SlashPineTech.Forestry.Versioning --version 2.0.0-rc.1
#r "nuget: SlashPineTech.Forestry.Versioning, 2.0.0-rc.1"
#:package SlashPineTech.Forestry.Versioning@2.0.0-rc.1
#addin nuget:?package=SlashPineTech.Forestry.Versioning&version=2.0.0-rc.1&prerelease
#tool nuget:?package=SlashPineTech.Forestry.Versioning&version=2.0.0-rc.1&prerelease
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 | Versions 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. |
-
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 |