将nuget程序包推送到Github程序包注册表:响应过早结束发送请求时发生错误

问题描述

我成功设置了一个GitHub操作,该操作构建并打包了我的多目标NuGet程序包。

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1.5.0
      with:
        dotnet-version: 3.1.301
        # Authenticates packages to push to GPR
        source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
      env:
        NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
    
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1.0.1
    
    - name: Install dependencies
      run: msbuild /t:Restore
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}
    
    - name: Build
      run: msbuild /t:Pack /p:Configuration=Debug Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj
    
    - name: Copy
      run: copy Library/MintPlayer.MVVM/bin/Debug/*.nupkg .
    
    - name: PushNuget
      run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
    - name: PushGithub
      run: dotnet nuget push *.nupkg --no-symbols --skip-duplicate
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}

由于这是Xamarin.Forms包,因此我需要使用MSBuild SDK。

还原构建打包命令运行正常。我无法将p:OutputPath参数用于多目标nuget程序包(Issue can be tracked here)。这就是为什么我要进行构建并将文件复制到%cd%的原因。

推送到nuget.org的工作正常,但推送到我的github feed失败,结果如下:

Output of the push to github feed

我无法找出问题所在。有谁知道为什么推送到GitHub失败的原因?

这也是成功推送至GPR的示例,因此未提供API密钥的警告也不是问题的原因:

Successful push to GitHub Package Registry

Same question on github.community

解决方法

万一链接失效:现在看来,当您要将包推送到GitHub feed时,可以使用nuget.exe而不是dotnet nuget来解决此问题。

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1.5.0
      with:
        dotnet-version: 3.1.301
        # Authenticates packages to push to GPR
        source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
      env:
        NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
    
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1.0.1
    
    - name: Install dependencies
      run: msbuild /t:Restore
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}
    
    - name: Build
      run: msbuild /t:Pack /p:Configuration=Debug Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj
    
    #- name: Test
    #  run: dotnet test --no-restore --verbosity normal
    
    - name: PushNuget
      run: dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
    
    - name: PushGithub
      run: nuget.exe push "**/*.nupkg" -NoSymbols -SkipDuplicate
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}

这似乎也修复了GPR被忽略的--skip-duplicate标志。另外,请勿在您的步骤中使用p:OutputPathoutput-path选项,因为对于多目标nuget程序包,它仅打包UWP目标DLL。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...