skip to Main Content

I am new to GitHub actions.
I have created a ci.main workflow. Below is my code.

After running I can’t view the package in the repository section.

jobs:
  build:
    runs-on: ubuntu-latest  
    steps:
     
    - name: Checkout
      uses: actions/checkout@v2
     
    - name: Build
       run: >
            dotnet pack package 
                   -p:Version=1.0.0 
                   -c Release 
                   -o ./location 
                   --include-source  
        
    - name: Push
      run: >
           dotnet nuget push 
           ./location/*.nupkg 
           --source "https://nuget.pkg.github.com/orginization/index.json" 
           --api-key xxxxxxx --skip-duplicate

enter image description here

2

Answers


  1. As your package is pushed successfully but it’s not visible under your repository packages, you need to verify the organization packages as well. You may follow the Viewing packages docs to do that.

    Also, according to Connecting a repository to a package:

    When you publish a package that is scoped to a personal account or an organization, the package is not linked to a repository by default.

    So, you have to manually link the package to your repository if it’s already published by following the steps mentioned in the docs above.

    And, according to Publishing a package:

    If you specify a RepositoryURL in your nuget.config file, the published package will automatically be connected to the specified repository.

    So, to make it automatically connect to your repository, you’ll have to update your nuget.config file accordingly.

    Login or Signup to reply.
  2. There are a handful of ways to accomplish this:

    1. Automagically

    If you publish with the generated token GitHub will automatically attach the repo to the package. Just ensure you have added write permissions on the job:

    jobs:
      build:
        runs-on: ubuntu-latest
        permissions:
          packages: write
        steps:
    ...
        - name: Push
          run: >
               dotnet nuget push 
               ./location/*.nupkg 
               --source "https://nuget.pkg.github.com/orginization/index.json" 
               --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
    

    2. Manually

    This is the easiest method, but will have to be done for every package you publish.

    Go to the package page and connect the desired repository repositories: https://github.com/orgs/{org}/packages/nuget/{package}

    Note that this appears to be a one-time operation, you cannot undo this without deleting your package and re-pushing.

    Docs

    3. Via Configuration

    From docs, by virtue of having 3a, 3b is generated with dotnet pack, but you can manually add to the nuspec if need be.

    3a. .csproj

    Add the RepositoryUrl

    <RepositoryUrl>https://github.com/{org}/{repo}</RepositoryUrl>
    

    3b. .nuspec

    Add the repository

    <repository url="https://github.com/{org}/{repo}" />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search