diff --git a/.github/workflows/dotnet-build-and-release.yml b/.github/workflows/dotnet-build-and-release.yml index beba323..1c2bee0 100644 --- a/.github/workflows/dotnet-build-and-release.yml +++ b/.github/workflows/dotnet-build-and-release.yml @@ -42,9 +42,7 @@ jobs: 3.1.x 6.0.x 8.0.x - - - name: Setup MSBuild - uses: keyfactor/setup-msbuild@v2 + 10.0.x - name: Setup build environment id: setup_env @@ -67,8 +65,29 @@ jobs: echo "Pre-release flagged: $($isPreRelease)" echo "IS_PRE_RELEASE=$($isPreRelease)" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append - dotnet nuget add source https://nuget.pkg.github.com/Keyfactor/index.json -n github -u ${{ github.actor }} -p ${{ secrets.token }} --store-password-in-clear-text - nuget restore $slnPath -Project2ProjectTimeout 240 + # Register the Keyfactor NuGet feed with credentials. + # If the source URL is already registered (e.g. via a repo nuget.config), + # find its name and update credentials rather than failing. + $addOutput = dotnet nuget add source https://nuget.pkg.github.com/Keyfactor/index.json ` + -n keyfactor -u ${{ github.actor }} -p ${{ secrets.token }} --store-password-in-clear-text 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Host "Source already registered; finding name to update credentials..." + $lines = dotnet nuget list source + $sourceName = $null + for ($i = 0; $i -lt $lines.Count; $i++) { + if ($lines[$i] -match 'nuget\.pkg\.github\.com/Keyfactor') { + if ($lines[$i-1] -match '^\s+\d+\.\s+(\S+)') { $sourceName = $Matches[1] } + } + } + if ($sourceName) { + dotnet nuget update source $sourceName -u ${{ github.actor }} -p ${{ secrets.token }} --store-password-in-clear-text + } else { + Write-Error "Could not locate Keyfactor NuGet source to update credentials." + exit 1 + } + } + + dotnet restore $slnPath - name: Increment Assembly Version if: env.CREATE_RELEASE == 'True' @@ -88,10 +107,10 @@ jobs: } } - - name: Execute MSBuild Commands + - name: Execute dotnet build run: | $newVer = "${{ inputs.release_version || '1.0.0' }}".TrimStart('v').Split('-')[0] - MSBuild.exe $Env:SOLUTION_PATH -p:RestorePackagesConfig=false -p:Configuration=Release -p:Version=$newVer + dotnet build $Env:SOLUTION_PATH --no-restore -c Release -p:Version=$newVer - name: Read Target Frameworks id: read_target_frameworks diff --git a/.github/workflows/starter.yml b/.github/workflows/starter.yml index 680eaa3..2be1643 100644 --- a/.github/workflows/starter.yml +++ b/.github/workflows/starter.yml @@ -106,7 +106,7 @@ jobs: call-dotnet-build-and-release-workflow: needs: [ call-get-primary-language, call-assign-from-json-workflow, call-create-github-release-workflow ] if: needs.call-get-primary-language.outputs.primary_language == 'C#' - uses: keyfactor/actions/.github/workflows/dotnet-build-and-release.yml@v4 + uses: keyfactor/actions/.github/workflows/dotnet-build-and-release.yml@dotnet10-support with: release_version: ${{ needs.call-create-github-release-workflow.outputs.release_version }} release_url: ${{ needs.call-create-github-release-workflow.outputs.release_url }}