Build, Package and Push .NET packages
Add steps to build and package a .NET application and then push the package to Azure Artifacts using Harness CI pipelines.
Overview
This article will guide you through the following steps:
Building and packaging .NET applications.
Pushing packages to Azure Artifacts.
Downloading and using packages from Azure Artifacts.
Prerequisites
Obtain Azure DevOps personal access token (PAT) with repo permissions: To configure, you need access to an Azure DevOps account with the necessary permissions to push packages to Azure Artifacts. For steps, refer to the documentation on creating an Azure DevOps PAT.
Store the Azure DevOps PAT as a Harness Secret Create a Harness secret to store the obtained Azure DevOps PAT. In the example below, a secret with the identifier
Azure_DevOps_PATis used. If you have already created a secret, update theNUGET_PAT="<+secrets.getValue('Azure_DevOps_PAT')>"line in the pipeline with the secret identifier.
Add the Build, Package, and Push steps to your pipeline
In your pipeline's Build stage, add these Run steps to build, package, and push packages. Here is a YAML example:
identifier: BuildPackagePush_NET_Packages
name: Build Package and Push .NET Packages
pipeline:
tags: {}
stages:
- stage:
name: Build and Push .NET Package
identifier: Pull_and_Push
description: ""
type: CI
spec:
cloneCodebase: false
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}
execution:
steps:
- step:
type: Run
name: Build and Package DOTNET
identifier: Build_and_Package_DOTNET
spec:
connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
image: mcr.microsoft.com/dotnet/sdk:8.0
shell: Sh
command: |-
dotnet new console --framework net8.0 --use-program-main
dotnet build --configuration Release
dotnet pack -c Release --version-suffix <+pipeline.sequenceId>
- step:
type: Run
name: Push DOTNET Package
identifier: Run_1
spec:
connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
image: mcr.microsoft.com/dotnet/sdk:8.0
shell: Sh
command: |-
# Add Azure Artifacts Feed Nuget Source
NUGET_PAT="<+secrets.getValue("Azure_DevOps_PAT")>"
NUGET_SOURCE="https://pkgs.dev.azure.com/AZURE_ORGANIZATION/_packaging/AZURE_ARTIFACTS_FEED/nuget/v3/index.json"
dotnet nuget add source $NUGET_SOURCE -n azuresource -u user -p $NUGET_PAT --store-password-in-clear-text
# Push the .NET package
dotnet nuget push ./bin/Release/PACKAGE_NAME.1.0.0-<+pipeline.sequenceId>.nupkg --source azuresource --api-key AzureDevOps
- step:
type: Run
name: Download DOTNET Package
identifier: Run_3
spec:
connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
image: mcr.microsoft.com/dotnet/sdk:8.0
shell: Sh
command: |-
mkdir newproject && cd newproject
dotnet new console
# Download the .NET package
dotnet add package Harness -v 1.0.0-<+pipeline.sequenceId>
caching:
enabled: false
paths: []When you run the pipeline, you can observe the step logs on the build details page.
If the steps succeed, you can find the package in your Azure Artifacts feed.
Last updated
Was this helpful?