Austin, Code, Life...


Orchestrating Visual Studio Code : Part 7 : NuGet Deployment

2nd May 2018

In this part, we will learn how to integrate NuGet package packing and deployment into our project.

The NuGet Script

We will add the method nugetPublish() to .vscode/tasks.json. This will search all projects in the solution that contain a .nuspec file, run dotnet pack, and curl upstream to NuGet.

nugetPublish () {

    echo -en "${YELLOW} Using Key: $nugetKey ${RESTORE}\n"

    [email protected]

    if [[ -z buildEnvironment ]]; then

    shopt -s nullglob # hide hidden

    cd src

    for dir in */ ; do # iterate projects
        [ -e "$dir" ] || continue

        cd $dir

        for nuspec in *.nuspec; do

            echo -e "${YELLOW}Found nuspec for ${projectName} ${RESTORE}"

            dotnet pack \
            -c $buildEnvironment \
            --include-source \

            echo -e "${YELLOW}Publishing: ${projectName}.$nugetVersion ${RESTORE}"

            curl \
            -H 'Content-Type: application/octet-stream' \
            -H "X-NuGet-ApiKey: $nugetKey" \
            $nugetFeedUri \
            --upload-file bin/$buildEnvironment/${projectName}.$nugetVersion.nupkg


        cd $ROOT_DIR


You can also use a MyGet feed with the variable $nugetFeedUri in this script.

The NuGet Task

We will add the task nuget-publish to the .vscode\tasks.json file:

    "label": "nuget-publish",
    "type": "shell",
    "osx": {
        "command": "bash ./scripts/ nugetPublish"
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": true,
        "panel": "dedicated"
    "problemMatcher": [],
    "windows": {
        "command": ".\\scripts\\project-tasks.ps1 -NugetPublish"


After adding a project with a .nuspec to your solution, press F1 and select the task nuget-publish. You will see the project get built, packed, and uploaded to NuGet or MyGet.

+ Deploying nuget packages to nuget feed

 Using Key: 00000000-0000-0000-0000-000000000000

Found nuspec for MyApp.NuGetProject
Microsoft (R) Build Engine version for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for ...
   Publishing: MyApp.NuGetProject.1.0.0
    The package has been created.

Uploaded nuspec for MyApp.NuGetProject

Instead of storing your api-key in source code, the script looks for an environment variable NUGET_KEY. You also need to set the NuGet|MyGet feed uri to the one provided from your account.

The Source Code

You can find the source code for this article in the following repository under the part-7-nuget-deployment branch:

Next Post : Part 8 : CI Integration

In the next post we will learn how integrate our tasks and scripts in our Continuous Build Server.

Let's build this!!

Previous Post : Unit Test Code Coverage

Software/DevOps Architect based in Austin, Texas living on tacos and code.

View Comments