DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Code Reviews: Building an AI-Powered GitHub Integration
  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization

Trending

  • The Smart Way to Talk to Your Database: Why Hybrid API + NL2SQL Wins
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Integration Isn’t a Task — It’s an Architectural Discipline
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Build, Publish and Deploy NuGet Package Using Github Actions

Build, Publish and Deploy NuGet Package Using Github Actions

In the modern era of DevOps automation has become more popular whereas creating/uploading packages has become the thing of the past.

By 
Harsh Gupta user avatar
Harsh Gupta
·
Jul. 01, 20 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
7.6K Views

Join the DZone community and get the full member experience.

Join For Free

In the modern era of DevOps automation has become more popular whereas creating/uploading packages has become the thing of the past. Moreover, day by day the packages count is increasing in the developer’s life. So, it is not easy to build, publish, and deploy all the packages manually on NuGet.org. We can manage a few packages (1-2) manually but, if we need to manage more packages (5,10 and so on). Then it will become a tedious job.

Using GitHub's actions, we can make this process fully automatic.

Here is the step by step guide to automate build, publish, and deploy (release) package to NuGet.

Step 1: Create a new repository on GitHub and uplaod your code.

Step 2: Create a GitHub Action, which makes it easy to build and publish. When we are creating a workflow, it creates a .yaml file. In this example, I am creating a workflow for .net core (c#).

workflow

Workflow

Step 3: The previous step creates the workflow for .NET Core environment. It has a predefined structure which is the nice starting point for build and test. It has the below sample code.

JavaScript
x
25
 
1
name: .NET Core  
2
  
3
on:  
4
  push:  
5
    branches: [ master ]  
6
  pull_request:  
7
    branches: [ master ]  
8
  
9
jobs:  
10
  build:  
11
  
12
    runs-on: ubuntu-latest  
13
  
14
    steps:  
15
    - uses: actions/checkout@v2  
16
    - name: Setup .NET Core  
17
      uses: actions/setup-dotnet@v1  
18
      with:  
19
        dotnet-version: 3.1.101  
20
    - name: Install dependencies  
21
      run: dotnet restore  
22
    - name: Build  
23
      run: dotnet build --configuration Release --no-restore  
24
    - name: Test  
25
      run: dotnet test --no-restore --verbosity normal  


Workflow code

Workflow code

Step 4: The above default code is enough to build and test the code. But we have a requirement to publish the package at NuGet.org. For this, we need to add a publish step in .yaml file.

Note: I have added the working directory tag as I have multiple projects in the same solution. 

JavaScript
xxxxxxxxxx
1
 
1
- name: Publish  
2
  uses: brandedoutcast/publish-nuget@v2.5.2  
3
  with:   
4
   PROJECT_FILE_PATH: Extensions/Extensions.csproj  
5
   NUGET_KEY: ${{secrets.NUGET_API_KEY}} 


code for publish

Code for Publish

Brandedoutcast has created a reusable GitHub Action to publish NuGet packages. This action looks for changes to the <version>{}</version> tag in the .csproj file.

While deploying on NuGet.org we need an API key to validate this. For this, we are using the variable.

Step 5: Create the API key from NuGet.org and then add this under the Settings>Secrets in GitHub repository. Create a variable name “NUGET_API_KEY”.

settings and secrets

Settings

Step 6: Save your .yaml file and start the action. You will see that the solution will be built and published on NuGet.org.

nuget.org

Build

Published Done

Published Done

Step 7: Package on NuGet.org.

validating package

Package

Summary: Whenever we are updating the package and pushing the code in the master branch then the GitHub action will initiate automatically and push the package to NuGet.org. Now, we don’t need to manage our packages manually and no need to worry about the number of packages.

Try this and enjoy it!

GitHub Build (game engine) NuGet .NET

Opinions expressed by DZone contributors are their own.

Related

  • Code Reviews: Building an AI-Powered GitHub Integration
  • How to Build Real-Time BI Systems: Architecture, Code, and Best Practices
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!