Skip to content

Commit 5a3c3b2

Browse files
ci: adds GitVersioning for automated versioning
Integrates Nerdbank.GitVersioning to automate versioning based on Git tags and history. This change introduces: - Version information using `version.json`. - NuGet package upload of symbol packages (.snupkg) to improve debugging. - Versioning information in the README file to improve user awareness. This will allow pre-release versions on branches and PRs, and stable versions on tags.
1 parent f6f07b8 commit 5a3c3b2

5 files changed

Lines changed: 26 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
$projects = Get-ChildItem .\tests -Recurse -Filter *.csproj | ForEach-Object { $_.FullName }
6262
foreach ($p in $projects) {
6363
Write-Host "Testing $p"
64-
dotnet test $p -c Debug --no-build --logger "trx;LogFileName=$(Split-Path -LeafBase $p).trx"
64+
dotnet test $p -c Debug --logger "trx;LogFileName=$(Split-Path -LeafBase $p).trx"
6565
}
6666
6767
# Pack for validation on all events; only upload artifacts on push (not PR)
@@ -74,12 +74,13 @@ jobs:
7474
dotnet pack $_.FullName -c Release --no-build -o .\artifacts\nuget
7575
}
7676
77-
- name: Upload NuGet artifacts (pushes only)
78-
if: github.event_name == 'push'
77+
- name: Upload NuGet artifacts
7978
uses: actions/upload-artifact@v4
8079
with:
8180
name: nuget-packages
82-
path: artifacts/nuget/*.nupkg
81+
path: |
82+
artifacts/nuget/*.nupkg
83+
artifacts/nuget/*.snupkg
8384
if-no-files-found: error
8485
retention-days: 7
8586

@@ -110,6 +111,7 @@ jobs:
110111

111112
- name: Push packages to NuGet.org
112113
env:
114+
# Accept either secret name: NUGET_API_KEY
113115
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
114116
shell: pwsh
115117
run: |

Directory.Packages.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<!-- Shared package versions for src/* projects -->
44
<PackageVersion Include="JetBrains.Annotations" Version="2025.2.2" />
55

6+
<!-- Versioning -->
7+
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.146" />
8+
69
<!-- Microsoft.Extensions line (pinned newer line for net472+) -->
710
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
811
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ Call `StopAsync` at shutdown to flush hosted services and logs.
269269
* Workflow: `.github/workflows/ci.yml`
270270
* Runs on Windows
271271
* Builds `src/*` in Release, runs tests in Debug
272+
* Uses Nerdbank.GitVersioning (version.json) – prerelease versions on branches/PRs; stable on tags matching `vMAJOR.MINOR.PATCH`
272273
* Packs NuGet on tag push (`v*`) → publishes to NuGet.org
274+
* Uploads `.nupkg` and `.snupkg` as workflow artifacts on PRs and pushes
273275
* Needs `NUGET_API_KEY` secret configured
274276
275277
---

eng/Directory.Build.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(MSBuildProjectDirectory)', '[\\/]src([\\/]|$)')) AND !$([System.Text.RegularExpressions.Regex]::IsMatch('$(MSBuildProjectName)', '\\.Tests$')) AND !$([System.Text.RegularExpressions.Regex]::IsMatch('$(MSBuildProjectDirectory)', '[\\/]examples([\\/]|$)'))">
1313
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1414
<NoWarn>$(NoWarn);1591</NoWarn>
15-
<!-- Keep AssemblyVersion stable to reduce binding churn -->
16-
<AssemblyVersion>1.0.0.0</AssemblyVersion>
1715
<!-- Package license expression for NuGet -->
1816
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1917
<!-- Enable central package management for src projects -->
@@ -27,6 +25,11 @@
2725
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2826
</PropertyGroup>
2927

28+
<!-- Add NBGV to src projects (dev dependency) -->
29+
<ItemGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(MSBuildProjectDirectory)', '[\\/]src([\\/]|$)'))">
30+
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" />
31+
</ItemGroup>
32+
3033
<!-- Conditional strong-name signing for src in Release (only when key is present) -->
3134
<PropertyGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(MSBuildProjectDirectory)', '[\\/]src([\\/]|$)')) AND '$(Configuration)' == 'Release' AND Exists('$(MSBuildThisFileDirectory)HostBridge.snk')">
3235
<SignAssembly>true</SignAssembly>

version.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3+
"version": "1.0",
4+
"publicReleaseRefSpec": [
5+
"^refs/tags/v\\d+\\.\\d+\\.\\d+(?:-.*)?$"
6+
],
7+
"cloudBuild": {
8+
"setVersionVariables": true
9+
}
10+
}

0 commit comments

Comments
 (0)