📗
Everyday Cheat Sheets
  • README
  • Build
    • Architecture
      • API Management
        • Kong
      • Authentication
        • Keycloak
        • Okta
      • Cloud Native
      • Design Patterns
      • Design Principles
      • IaC
      • IoT
      • Message Broker
      • Methods
      • Networking
      • Payment
        • Stripe
      • Testing
    • Code lifecycle (ALM)
      • Automation Pipelines
        • Argo CD
        • CircleCI
        • Flux
        • Keptn
        • Travis
      • Azure DevOps
        • Azure Pipelines
      • Chef
      • GitHub
        • GitHub Actions
      • Nexus
      • Promyze
      • RunDeck
      • SaltStack
      • Sonar
      • Tuleap
    • Containers & Cloud Native
      • Argo Workflows
      • Containerization
        • Docker
          • Docker CLI
        • containerd
        • cri-o
      • CNAB
      • Dapr
      • Envoy
      • Fluentd
      • Knative
      • Kubernetes
        • Cluster API
        • etcd
        • Helm
        • k3d
        • kind
        • Kubectl
        • MetalLB
        • Minikube
      • Open Application Model (OAM)
      • Unleash
    • Data storage
      • MySQL
      • MongoDB
        • Atlas
        • Compass
        • Evergreen
        • MongoDB 4.2
        • MongoDB 5.0
        • MongoDB design
        • MongoDB events
        • MongoDB driver for .NET
        • Ops Manager
        • Realm
      • Oracle
      • Redis
      • SQL Server
      • PostgreSQL
    • Frameworks & libraries
      • Angular
        • Angular CLI
        • Angular events
      • .NET
        • ASP.NET Core
        • Blazor
        • .NET 5.0
        • .NET 6.0
        • .NET CLI
        • .NET Core
        • .NET Events
        • .NET Logging
        • .NET Testing
        • NuGet
        • WPF
        • Xamarin
      • gRPC
      • Ionic
      • Jekyll
      • Node.js
        • Express
        • NPM
      • React
        • React Native
      • Redux
    • IDE
      • Visual Studio 2022
    • Languages
      • C#
        • C# 8.0
      • ECMAScript
      • GraphQL
      • JavaScript
        • webpack
        • Yarn
      • MS-DOS
      • PHP
      • PowerShell
      • Python
      • Swagger
      • TypeScript
    • Messaging
      • Azure Service Bus
      • RabbitMQ
    • Testing
    • Workstation
      • QGIS
      • Visual Studio 2019
      • Windows 10
      • Windows Subsystem for Linux
  • Collaborate
    • Marp
    • Microsoft 365
      • Microsoft Graph
      • SharePoint Framework
        • Fluent UI
        • SharePoint Framework UI components
  • Run
    • Cloud computing
      • Alibaba
      • AWS
      • Azure
        • Azure AD
        • Azure CLI
        • Azure Container Registry
        • Azure Portal
        • Azure Service Bus
      • Firebase
      • OVH
    • Hardware
      • Single-board computers
        • Odroid
        • Raspberry Pi
    • Infrastructure automation
      • Azure Resource Manager
      • Packer
      • Pulumi
      • Puppet
      • Terraform
        • HCL
        • Terraform CLI
        • Terraform Providers
    • Networking
      • HAProxy
      • nginx
    • Observability
      • Grafana Labs
        • Grafana
        • Loki
        • Tempo
      • OpenTelemetry
      • Prometheus
      • Splunk
    • Security
      • Falco
    • Systems
      • Linux
        • CentOS
        • eBPF
        • Linux Kernel
        • Rocky
        • Ubuntu
      • Windows Server
    • Virtualization
      • Hyper-V
      • Vagrant
  • Optimize
    • DevOps
  • Join
    • Companies
      • HashiCorp
Powered by GitBook
On this page
  • Presentation
  • Common packages
  • NuGet CLI
  • CLI documentation
  • CLI useful commands
  • Recipes
  • Create a package
  • Publish NuGet packages from AzureDevOps
  • Host public/private feeds
  • How-to
  • Host your NuGet feeds
  • Publish a NuGet package from VSTS

Was this helpful?

Export as PDF
  1. Build
  2. Frameworks & libraries
  3. .NET

NuGet

Previous.NET TestingNextWPF

Last updated 1 year ago

Was this helpful?

NuGet is the package manager for .NET

→ ,

Presentation

An essential tool for any modern development platform is a mechanism through which developers can create, share, and consume useful code. Often such code is bundled into "packages" that contain compiled code (as DLLs) along with other content needed in the projects that consume these packages.

For .NET, the Microsoft-supported mechanism for sharing code is NuGet, which defines how packages for .NET are created, hosted, and consumed, and provides the tools for each of those roles.

→

Common packages

Name
Website
Source

AutoMapper

Dapper

FluentAssertions

FluentValidation

ImageSharp

MediatR

Moq

Selenium WebDriver

xUnit

NuGet CLI

CLI documentation

CLI useful commands

  • Self-update: nuget update -self

  • Create spec file: nuget spec

  • Create packages: nuget pack

Recipes

Create a package

Publish NuGet packages from AzureDevOps

Host public/private feeds

Name
Site

Azure Packages

Provided by Azure DevOps

MyGet

ProGet

NuGet Server

NuGet Gallery

How-to

Host your NuGet feeds

Solutions available (list not exhaustive!):

Pros: very easy to setup (less than 5 minutes), secure, free account (limited but more than enough for personal projects and evaluate), available on internet, works well with VSTS, no maintenance of infra cost

Pros: natively integrated with VSTS Build, no maintenance of infra cost

Cons: seems like the only free solution BUT time needed to setup (creation of the solution, build & deploy) and maintain the server hosting the solution (+ infra cost), by default no backup or feed on internet

4/ Sonatype Nexus

Cons: community version do not manage NuGet feeds AND infra/maintenance cost plus feeds not on internet by default

Tips:

  • <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
        <add key="MyGet Devpro" value="https://www.myget.org/F/devpro-public/api/v3/index.json" />
      </packageSources>
    </configuration>

Publish a NuGet package from VSTS

Prerequisites:

  • NuGet server (needs to be defined):

    • In your VSTS project Settings section (wheel icon) go in "Services" page

    • In "Endpoints" click on "New Service Endpoint" and select "NuGet"

    • Fill the different elements (this is very easy if you are using MyGet, the feed URL and ApiKey have been displayed when you configured your feed)

Steps:

  • .NET Core > Restore: nothing particular here (don't forget the NuGet.config file if you are using other feeds than nuget.org)

  • .NET Core > Build: nothing particular here

  • .NET Core > Test: nothing particular here

  • NuGet > NuGet push:

    Target feed location = External NuGet server (including other accounts/collections)

    Nuget Server = the name of the server you defined earlier

Tips:

  • 1/ Update your build definition in VSTS 2/ Update your project file and add VersionPrefix and VersionSuffix 3/ Use MSBuild to control how you build your NuGet packages

,

→

1/

2/ with

3/ Host & deploy a web application referencing

Do not forget to add a NuGet.config file at the root of the solutions that will use the library (see and ). Otherwise you won't be able to do on build systems such as VSTS. Example:

→

.NET Core > dotnet pack: as of today (Feb 2018), you cannot use "NuGet pack in VSTS" but you can do a "dotnet pack" instead (ref discussion on ).

By default, the NuGet package will always have the version 1.0.0 (). There are 3 solutions:

nuget.org
learn.microsoft.com
docs.microsoft.com/what-is-nuget
NuGet CLI reference
Package creation workflow
Versioning and publishing NuGet packages automatically using Azure DevOps Pipelines
Customize your build (C#, Visual Basic)
docs.microsoft.com
MyGet
VSTS
Package Management VSTS extension
NuGet.Server
Configuring NuGet behavior
NuGet.Config reference
dotnet restore
docs.microsoft.com
github
question raised on Stackoverflow
automapper.org
dapper-tutorial.net
GitHub
fluentassertions.com
fluentvalidation.net
sixlabors.com
GitHub
GitHUb
GitHub
GitHub
myget.org
Working with upstream sources
inedo.com
nugetserver.net
GitHub