繁体   English   中英

使用 GitHub 操作发布 NuGet package 到 GitHub 包

[英]Publishing NuGet package to GitHub Packages Using GitHub Actions

我正在尝试创建我的 .NET 库的 NuGet package,并使用 GitHub 操作将其发布到 GitHub 包 NuGet 注册表。

我被困在发布部分。 我正在使用以下命令:

dotnet nuget push "bin/Release/MyApp.${{ steps.get-version.outputs.version }}.nupkg" source --username MY_GITHUB_USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/MY_COMPANY_GITHUB_ACCOUNT/index.json"

我得到的错误是:

无法识别的选项“--用户名”

您可能已经注意到,我正在获取我在.csproj文件中设置的版本号,以便找出 nuget 文件名。

我需要发出什么命令才能在构建后将我的 NuGet package 推送到我的私人 GitHub 包注册表中?

这是完整的release.yml文件:

# 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: Publish MyApp NuGet to GitHub Packages

on:
  pull_request:
    branches: [ "master" ]

jobs:
  build-pack-n-ship:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 6.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --no-restore
    - name: Create NuGet package
      run: dotnet pack --configuration Release
    - name: Get version
      uses: kzrnm/get-net-sdk-project-versions-action@v1
      id: get-version
      with:
        proj-path: MyApp/MyApp.csproj
    - name: Add GitHub Packages as Source
      run: dotnet nuget add source --username MY_GITHUB_USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/MY_GITHUB_COMPANY_ACCOUNT/index.json"
    - name: Publish to GitHub Packages
      run: dotnet nuget push "bin/Release/MyApp.${{ steps.get-version.outputs.version }}.nupkg" --source github

我通常只添加source ,然后在推送时我只设置--source

- name: Add nuget source
  run: dotnet nuget add source --username YOURSERNAME --password ${{ secrets.NUGET_API_KEY }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/YOURSERNAME/index.json"
- name: Publish MyApp
  run: |
      dotnet pack -p:Version=$GITVERSION_SEMVER --configuration Release MyApp.csproj
      dotnet nuget push MyApp/bin/Release/MyApp.*.nupkg --source "github"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM