'dotnet build' command not finding NuGet packages (they exist)

I ran into a similar issue solved by clearing global packages and cache with dotnet nuget locals all --clear as explained here.


I've resolved the issue by specifying where dotnet build should look for the NuGet packages. It that within the image it doesn't look at the right location (although I'm not sure where it is looking either...)

I've specified the location with the --packages option. This option is listed in the dotnet restore documentation, but not in the dotnet build ones, even though it is available there as well (and you need it there, specifically).

You can specify it as follows:

dotnet restore --packages <path>

and

dotnet build --packages <path>

It works with the --no-restore option as well, if you need that.


My final Jenkinsfile looks as follows:

pipeline {
    agent {
        docker {
            image 'microsoft/dotnet:2.1-sdk'
        }
    }
    environment {
        HOME = '.'
    }
    stages {
        stage('pre-build') {
            steps {
                // logging tooling versions
                sh 'dotnet --info'
                sh 'dotnet nuget locals all --list'
                sh 'dotnet clean'
            }
        }
        stage('build') {
            steps {
                sh 'dotnet build --packages ./.nuget/packages'
            }
        }
        stage('test') {
            steps {
                sh 'echo no test project configured'
                // sh 'dotnet test'
            }
        }
    }
}