Create nuget-publish.yml #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |