将 nuget 包发布到 GitHub 包时禁止 GITHUB_TOKEN 403

Viv*_*ere 2 c# github nuget github-actions

我按照这些资源设置了 GitHub Actions 工作流程来构建、测试 dotnet 库并将其发布到 GitHub 包:

这些文章确实很有帮助,但是我遇到了一个他们都没有讨论的问题:

将 MagicLibrary.0.1.3.nupkg 推送到“https://nuget.pkg.github.com/vivere-dally”... PUT https://nuget.pkg.github.com/vivere-dally/ warn :您的请求无法通过 GitHub Packages 服务进行身份验证。请确保您的访问令牌有效并且配置了适当的范围。禁止https://nuget.pkg.github.com/vivere-dally/ 218ms 错误:响应状态代码不表示成功:403(禁止)。

这是我的工作流程文件:

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Release

on:
  push:
    tags:
    - "v[0-9]+.[0-9]+.[0-9]+"

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Verify commit exists in origin/main
      run: |
        git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
        git branch --remote --contains | grep origin/main
    
    - name: Set VERSION env var from tag
      run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
    

    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 6.0.x

    - name: Restore dependencies
      run: dotnet restore
      working-directory: ./MagicLibrary

    - name: Build
      run: dotnet build --configuration Release /p:Version=${VERSION} --no-restore
      working-directory: ./MagicLibrary

    - name: Test
      run: dotnet test --configuration Release /p:Version=${VERSION} --no-build --verbosity normal
      working-directory: ./MagicLibrary

    - name: Pack
      run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .
      working-directory: ./MagicLibrary

    - name: Push
      run: dotnet nuget push MagicLibrary.${VERSION}.nupkg --source "https://nuget.pkg.github.com/vivere-dally/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}
      working-directory: ./MagicLibrary
Run Code Online (Sandbox Code Playgroud)

为什么没有GITHUB_TOKEN所需的权限?