title: 'dotnet build' command not finding NuGet packages (they exist)
body: <p>I'm trying to build my .NET Core 2.1 application from the command-line on my Jenkins server.</p>
  <p>It builds fine on my local machine (Windows 10, Visual Studio 2017 Enterprise), and if I manually build it on the server Jenkins is running on (manually checkout Git repository and running <code>dotnet build</code>). It's only when I'm doing it through Jenkins in a Docker container that it fails.</p>
  <p>The error:
  <code>/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]</code></p>
  <p>The package exists in <code>~/.nuget/packages/</code>.</p>
  <p>I'm aware my Jenkinsfile is a bit weird at the moment, but that has to do with me trying to make this all work. It seems <code>dotnet restore</code> is working fine, but <code>dotnet build</code> is somehow not locating these files.</p>
  <p>I've tried specifying the package directory (through the environment variable, with <code>dotnet restore --sources</code> and <code>dotnet build --sources</code>.</p>
  <p>I attached pretty much anything I could think of at the moment, but if I forgot something please tell. I'm pretty lost at the moment.</p>
  <p>My Jenkinsfile:</p>
  <pre><code>pipeline {
      agent {
          docker {
              image 'microsoft/dotnet:2.1-sdk'
          }
      }
      environment {
          HOME           = '.'
          NUGET_PACKAGES = './.nuget/packages/'
      }
      stages {
          stage('pre-build') {
              steps {
                  // logging tooling versions
                  sh 'dotnet --info'
                  sh 'find ~/.nuget/packages/microsoft.codequality.analyzers/ -type f'
                  sh 'dotnet nuget locals all --list'
                  sh 'dotnet restore'
                  // sh 'dotnet clean'
              }
          }
          stage('build') {
              steps {
                  // sh 'dotnet restore --force --no-cache'
                  // sh 'ls ./packages/'
                  // sh 'find ./packages/microsoft.codequality.analyzers/ -type f'
                  sh 'dotnet build --no-restore'
              }
          }
          stage('test') {
              steps {
                  sh 'no test project configured'
                  // sh 'dotnet test'
              }
          }
      }
  }
  </code></pre>
  <p>My .csproj</p>
  <pre><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp2.1&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;Folder Include=&quot;wwwroot\&quot; /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.App&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.CodeAnalysis.FxCopAnalyzers&quot; Version=&quot;2.6.2&quot;&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers&lt;/IncludeAssets&gt;
      &lt;/PackageReference&gt;
    &lt;/ItemGroup&gt;
  
    &lt;PropertyGroup&gt;
      &lt;CodeAnalysisRuleSet&gt;&lt;/CodeAnalysisRuleSet&gt;
      &lt;Features&gt;IOperation&lt;/Features&gt;
    &lt;/PropertyGroup&gt;
  
  &lt;/Project&gt;
  </code></pre>
  <p>Some build details:</p>
  <pre><code>$ docker --version
  Docker version 18.06.1-ce, build e68fc7a
  </code></pre>
  <p>Inside docker container:</p>
  <pre><code>$ dotnet --info
  .NET Core SDK (reflecting any global.json):
   Version:   2.1.403
   Commit:    04e15494b6
  
  Runtime Environment:
   OS Name:     debian
   OS Version:  9
   OS Platform: Linux
   RID:         debian.9-arm
   Base Path:   /usr/share/dotnet/sdk/2.1.403/
  
  Host (useful for support):
    Version: 2.1.5
    Commit:  290303f510
  
  .NET Core SDKs installed:
    2.1.403 [/usr/share/dotnet/sdk]
  
  .NET Core runtimes installed:
    Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  </code></pre>
  <hr />
  <pre><code>$ find ./.nuget/packages/microsoft.codequality.analyzers/ -type f
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/vb/Microsoft.CodeQuality.VisualBasic.Analyzers.dll
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/vb/Microsoft.CodeQuality.Analyzers.dll
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/cs/Microsoft.CodeQuality.Analyzers.dll
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/cs/Microsoft.CodeQuality.CSharp.Analyzers.dll
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/.signature.p7s
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/ThirdPartyNotices.rtf
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.CSharp.Analyzers.props
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.VisualBasic.Analyzers.props
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.Analyzers.props
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DesignRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DocumentationRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/PerformanceRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/UsageRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/ReliabilityRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/MaintainabilityRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/SecurityRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/PerformanceRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/MaintainabilityRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/UsageRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DocumentationRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/ReliabilityRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/NamingRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesDisabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/SecurityRulesEnabled.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DesignRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/NamingRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesDefault.ruleset
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.2.6.2.nupkg.sha512
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.2.6.2.nupkg
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.nuspec
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/tools/uninstall.ps1
  ./.nuget/packages/microsoft.codequality.analyzers/2.6.2/tools/install.ps1
  </code></pre>
  <hr />
  <pre><code>$ dotnet nuget locals all --list
  info : http-cache: ./.local/share/NuGet/v3-cache
  info : global-packages: ./.nuget/packages/
  info : temp: /tmp/NuGetScratch
  info : plugins-cache: ./.local/share/NuGet/plugins-cache
  </code></pre>
  <hr />
  <pre><code>$ dotnet restore
  
    Restoring packages for /var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj...
  
    Restore completed in 13.5 sec for /var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj.
  </code></pre>
  <hr />
  <pre><code>$ dotnet build --no-restore
  
  Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  /usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
  
  Build FAILED.
  
  /usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
      0 Warning(s)
      1 Error(s)
  </code></pre>