当前位置:  开发笔记 > 编程语言 > 正文

如何在GitHub操作中推送nuget包

如何解决《如何在GitHub操作中推送nuget包》经验,为你挑选了1个好方法。

我正在尝试使用GitHub操作从我的项目中生成NuGet包,并将其推送到(私有)GitHub注册表。

我的脚本([NAME]字段已删除):

name: Update NuGet

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    name: Update NuGet 
    steps:
      - uses: actions/checkout@master
      - uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '2.2.105'
      - name: Package Release
        run: |  
          cd [SOLUTION_FOLDER]
          dotnet pack -c Release -o out
      - name: Publish Nuget to GitHub registry
        run: dotnet nuget push ./[SOLUTION_FOLDER]/[PROJECT_FOLDER]/out/$(ls ./[SOLUTION_FOLDER]/[PROJECT_FOLDER]/out) -s https://nuget.pkg.github.com/[USERNAME]/index.json -k ${GITHUB_TOKEN}  
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 

日志输出:

info : Pushing [PROJECT_FOLDER].3.4.23.nupkg to 'https://nuget.pkg.github.com/[USERNAME]'...
info :   PUT https://nuget.pkg.github.com/[USERNAME]/
info : An error was encountered when fetching 'PUT https://nuget.pkg.github.com/[USERNAME]/'. The request will now be retried.
info : An error occurred while sending the request.
info :   The server returned an invalid or unrecognized response.
info :   PUT https://nuget.pkg.github.com/[USERNAME]/
info : An error was encountered when fetching 'PUT https://nuget.pkg.github.com/[USERNAME]/'. The request will now be retried.
info : An error occurred while sending the request.
info :   The server returned an invalid or unrecognized response.
info :   PUT https://nuget.pkg.github.com/[USERNAME]/
error: An error occurred while sending the request.
error:   The server returned an invalid or unrecognized response.
##[error]Process completed with exit code 1.

这是GitHub上最核心的问题(带有解决方法):https : //github.com/NuGet/Home/issues/8580



1> jwillmer..:

我切换到Windows映像,并根据@anangaur的示例使其工作。这是我的最终代码:

name: NuGet Generation

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: windows-latest
    name: Update NuGet 
    steps:

      - name: Checkout repository
        uses: actions/checkout@master

#  latest image has .NET already installed!
#      - name: Setup .NET environment
#        uses: actions/setup-dotnet@v1
#        with:
#          dotnet-version: '2.2.105' 

      - name: Build solution and generate NuGet package
        run: |  
          cd SOLUTION_FOLDER
          dotnet pack -c Release -o out  

      - name: Install NuGet client
        uses: warrenbuckley/Setup-Nuget@v1

      - name: Add private GitHub registry to NuGet
        run: nuget sources add -name "GPR" -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GITHUB_TOKEN }}

      - name: Push generated package to GitHub registry
        run: nuget push .\SOLUTION_FOLDER\PROJECT_FOLDER\out\*.nupkg -Source "GPR" -SkipDuplicate

推荐阅读
惬听风吟jyy_802
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有