Skip to content

Publish .NET 4.7 Package to NuGet #11

Publish .NET 4.7 Package to NuGet

Publish .NET 4.7 Package to NuGet #11

Workflow file for this run

name: Publish .NET 4.7 Package to NuGet
on:
release:
types: [published] # Triggers automatically when you publish a GitHub release
workflow_dispatch: # Allows you to manually trigger this build from the GitHub
jobs:
build-and-publish:
runs-on: windows-latest # Keeps Windows to ensure flawless legacy framework assembly mapping
permissions:
id-token: write # Required for Trusted Publishing / OIDC handshake
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x' # Needed to run modern build/pack tools
# 1. Parse the Git Tag and auto-increment the Minor version
- name: Calculate Next Version Number
id: versioning
shell: powershell
run: |
# Get the tag name from the GitHub event context (e.g., "v1.2")
$rawTag = "${{ github.event.release.tag_name }}"
# Handle edge case if no tag is found
if ([string]::IsNullOrEmpty($rawTag)) {
$rawTag = "1.0"
}
# Strip out any leading "v" if present
$cleanTag = $rawTag.TrimStart("v")
# Parse version array components
$versionParts = $cleanTag.Split('.')
# FIXED: Target explicit index [0] for major version
$major = [int]$versionParts[0]
# FIXED: Target explicit index [1] for minor version and increment it
$minor = 0
if ($versionParts.Length -gt 1) {
$minor = [int]$versionParts[1] + 1
}
# Construct the clean final package version (Major.IncrementedMinor.0)
$nextVersion = "$major.$minor.0"
Write-Host "The parsed tag was: $rawTag"
Write-Host "The computed auto-incremented NuGet version is: $nextVersion"
# Save this computed version to the step outputs for downstream use
echo "NEW_VERSION=$nextVersion" >> $env:GITHUB_OUTPUT
# 2a. Ensure MSBuild is available on the runner (Add this step)
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
# 2b. Emulate Visual Studio's Solution-level restore
- name: Restore Dependencies
run: |
msbuild "Reverse Engineering Toolkit.sln" /t:Restore /p:Configuration=Release /p:Platform="AnyCPU"
# 2c. Explicitly build the base dependency project FIRST
- name: Build BasicTools
run: msbuild "BasicTools\BasicTools.csproj" /p:Configuration=Release /p:Platform="AnyCPU"
# 2d. Explicitly build the dependent project SECOND
- name: Build HexTools
run: msbuild "HexTools\HexTools.csproj" /p:Configuration=Release /p:Platform="AnyCPU"
# 2e. Pack the compiled projects into packages safely using 'dotnet pack'
- name: Pack NuGet Packages
run: |
dotnet pack "Reverse Engineering Toolkit.sln" `
--configuration Release `
--no-build `
--output ./artifacts `
-p:Version="${{ steps.versioning.outputs.NEW_VERSION }}"
# 3. Authenticate with NuGet via Trusted Publishing (OIDC)
- name: NuGet Login
uses: NuGet/login@v1
id: login
with:
user: 'MakoInfused'
# 4. Push using the short-lived token generated by the login step
- name: Push to NuGet
run: |
dotnet nuget push ./artifacts/*.nupkg `
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" `
--source https://nuget.org `
--skip-duplicate