Skip to content

Create nuget-publish.yml #1

Create nuget-publish.yml

Create nuget-publish.yml #1

Workflow file for this run

name: Publish NuGet Package
on:
push:
branches:
- main # 触发工作流的分支
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0.x', '9.0.x'] # 设置多个 .NET 版本
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ matrix.dotnet-version }} # 使用矩阵中的 .NET 版本
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Pack
run: dotnet pack --configuration Release --no-build --output ./nupkg
- name: Publish to NuGet
if: github.ref == 'refs/heads/main' # 仅在推送到 main 分支时发布
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} # 从 GitHub Secrets 中获取 NuGet API 密钥
run: dotnet nuget push ./nupkg/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json