title: Jenkins Package Restore with nuget.config
body: <p>Currently working to get a new app to deploy using Jenkins and stuck on an issue with package restore.
  Please note...my focus is in dev, not DevOps so a lot of this is still pretty foreign to me.   So, I apologize in advance if it takes some back and forth for clarification.</p>
  <p>The project uses the following files:   jenkinsfile, docker-compose.bi.build.yml, build.sh, and nuget.config.   Those files are all listed below for reference.</p>
  <p><strong>Brief Overview:</strong></p>
  <p>I have 2 DLLs that are source controlled in 2 separate VS solutions (and seperate Git repos).   Those DLLs are:  AN.Infrastructure (infras) and AN.Domain.Core (domain).   domain depends on infras.   infras is some basic stuff...string extensions, etc. and doesn't have many depenedencies.   domain has more dependencies on things like EF, Postgres EF, AutoMapper, etc., but it also pulls in infras during the package restore process.   infras and domain are set up the same way as far as source control, jenkins, etc. are concerned (meaning I expect them to build nearly the same minus the extra dependencies).
  Currently, infras is building and deploying as it should so i know the process I have is working.</p>
  <p>The process goes like this:</p>
  <ul>
  <li>The jenkinsfile spins up a container based on the ci.build.yml file.
  This container is meant to build the source code and copy the output
  to a staged directory so that the rest of the process can
  package/deploy it.</li>
  <li>The build.sh script is executed inside the running container that is
  building the code and is doing the work to restore dependencies, kick
  off msbuild, and then package the artifacts.</li>
  </ul>
  <p><strong>Problem:</strong></p>
  <p>I can't get the domain solution to build thru Jenkins due to what appears to be missing package references.  The process throws the following error:</p>
  <blockquote>
  <p>Package Microsoft.EntityFrameworkCore.Analyzers, version 3.1.4 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.</p>
  </blockquote>
  <p><strong>What I Know:</strong></p>
  <ul>
  <li>I have proven the infras pipeline works end-to-end as I can navigate
  to and install the infras assembly via VS nuget UI to the domain
  solution on my local machine.  The domain solution builds and works
  as expected in this manner.</li>
  <li>I also know the code for domain is being pulled down to the jenkins
  server when the pipeline job is kicked off...I remoted into the
  workspace folder in /var/lib/jenkins to confirm.</li>
  <li>Also, I see all my echo printouts in the output from the build.sh
  script when the domain job runs.  So, the process is running like I
  expect, it just fails at package restore.</li>
  <li>Since infras is hosted on a Linux file share and not directly at
  nuget.org, I read that I have to use a nuget.config file next to the
  solution in order to configure the package sources so dotnet build
  knows where to restore the packages from.   I created that file and
  it is below.  I have tried with and without that file though and it
  fails both ways.</li>
  <li>I noticed that the MS.EF.Analyzers DLL is being pulled into the
  domain project indirectly via npgsql.entityframeworkcore.postgres
  dependency.   So, I decided to include npgsql in infras solution as
  well as I thought this would break that build also.   However, that
  wasn't the case.   infras built in Jenkins even after I pulled in
  that depenedency.</li>
  </ul>
  <p><strong>What I Have Tried:</strong></p>
  <p>You name it....I'm at 45 builds in Jenkins right now...each time trying something new (eg...with nuget.config, without nuget.config, etc.).   What I posted in the files below is the current state and what I have described in the question.   I am more than happy to answer any question, provide any additional info, or try whatever to get this resolved...just not sure where to go at this point.</p>
  <p><strong>Jenkinsfile:</strong></p>
  <pre><code>pipeline {
    agent any
    stages {
      stage('Build The Codes') {
        steps {
          sh '''sudo AN_BUILD_NUMBER=${BUILD_NUMBER} /usr/local/bin/docker-compose -f docker-compose.ci.build.yml up'''
        }
      }
      stage ('Deploy The Codes') {
        when {
          branch 'main'
        }
        steps {
          sh '''sudo cp ./src/AN.Domain.Core/bin/Release/*${BUILD_NUMBER}.nupkg /opt/nuget/development/'''            
        }
      }
      stage ('Deploy The Codes 2.0') {
        when {
          branch 'release'
        }
        steps {
          sh '''sudo cp ./src/AN.Domain.Core/bin/Release/*${BUILD_NUMBER}.nupkg /opt/nuget/production/'''            
        }
      }
    }
  }
  </code></pre>
  <p><strong>docker-compose.ci.build.yml:</strong></p>
  <pre><code>version: '3.8'
  
  volumes:
    nugetdirectory:
  
  services:
    ci-build:
      image: mcr.microsoft.com/dotnet/sdk:3.1
      volumes:
        - .:/src:z
        - nugetdirectory:/opt/nuget/production
      working_dir: /src
      environment:
        - &quot;AN_BUILD_NUMBER=${AN_BUILD_NUMBER}&quot;
  
      command:  /bin/bash -c &quot;sh ./build.sh&quot;
  </code></pre>
  <p><strong>build.sh:</strong></p>
  <pre><code>echo '*** Starting build process for AN.Domain project ***'
  
  echo 'Generate New Assembly Version'
  year=$(date '+%Y')
  month=$(date '+%m')
  day=$(date '+%d')
  version=&quot;${year}.${month}.${day}.${AN_BUILD_NUMBER}&quot;
  echo 'New Assembly Version: ' + $version
  
  echo 'Clean previous output directory for AN.Domain project'
  echo ' - Remove Docker publish directory'
  rm -rf obj/Docker/publish
  
  echo ' - Remove previous nuget packages'
  rm /src/src/AN.Domain.Core/bin/Release/*.nupkg    
  
  echo 'Clean output directory for AN.Domain project'
  dotnet clean
  
  echo 'Publish AN.Domain project'
  dotnet msbuild /t:Restore -target:Publish -property:Configuration=Release -property:OutputPath=obj/Docker/publish -property:Version=$version
  
  echo 'Copy NuGet packages to output directory'
  cp /src/src/AN.Domain.Core/bin/Release/*.nupkg obj/Docker/publish
  
  echo '*** Finishing build process for AN.Domain project ***'
  </code></pre>
  <p><strong>nuget.config:</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;configuration&gt;
    &lt;packageSources&gt;
      &lt;add key=&quot;nuget.org&quot; value=&quot;https://api.nuget.org/v3/index.json&quot; /&gt;
      &lt;add key=&quot;privateRepo&quot; value=&quot;/opt/nuget&quot; /&gt;
    &lt;/packageSources&gt;
    &lt;activePackageSource&gt;
      &lt;add key=&quot;All&quot; value=&quot;(Aggregate source)&quot; /&gt;
    &lt;/activePackageSource&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>UPDATES:</p>
  <ul>
  <li>I removed the domain project from the solution and created a brand new console app to test with.   This project built as expected when run via Jenkins.   I even added the dependency to npgsql which also brought in the MS.EF.Analyzers DLL that is causing the issue.</li>
  <li>I just added to the test console app the dependency on infras and
  this breaks the build with the same error.   So, it is definitely
  bringing in that custom nuget package that is causing the build
  error.</li>
  </ul>