title: DevOps Pipeline - can't find packages during build step
body: <p>I'm trying to shift an existing ASP.NET MVC web application away from TeamCity and on to Azure DevOps however I can't seem to get my pipeline to find the packages that it restored from the NuGet package restore task.</p>
  
  <p>The solution has multiple projects and they use a large number of NuGet packages. I've created a multi-step pipeline which currently has a NuGet Restore task and a VS Build task.</p>
  
  <p>The solution structure is like this:</p>
  
  <pre><code>\source
  ..\SolutionFolder
  ...Solution.sln
  ..\..\Project1
  ....Project1.csproj
  ..\..\Project2
  ....Project2.csproj
  ..\..\Packages
  azure-pipelines.yaml
  NuGet.config
  </code></pre>
  
  <p>The pipeline YAML looks like this:</p>
  
  <pre><code>trigger:
  - PipelineBranch
  
  pool:
    vmImage: 'windows-latest'
  
  stages:
  
  ## NuGet Restore ##
  - stage: nuget_restore
    displayName: 'Restore nuget packages'
    jobs:
    - job: nuget_package_restore
      steps:
      - task: NuGetCommand@2
        displayName: 'NuGet restore'
        inputs:
          command: 'restore'
          restoreSolution: 'source/SolutionFolder/Solution.sln'
          feedsToUse: 'config'
          nugetConfigPath: 'NuGet.Config'
          restoreDirectory: '$(Build.SourcesDirectory)\source\SolutionFolder\packages'
  
  ## Build ##
  - stage: build_for_int
    displayName: 'Build to int)'
    jobs:
    - job: run_build
      pool:
        vmImage: 'windows-latest'
      steps:
        - task: VSBuild@1
          displayName: 'Build Solution.sln (int)'
          inputs:
            solution: 'source/SolutionFolder/Solution.sln'
            msbuildArgs: '
            /p:DeployOnBuild=true 
            /p:WebPublishMethod=Package 
            /p:PackageAsSingleFile=true 
            /p:SkipInvalidConfigurations=true 
            /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
            platform: '$(BuildPlatform)'
            configuration: '$(BuildConfiguration)'
  </code></pre>
  
  <p>When the pipeline runs the restore task succeeds with the following outputs:</p>
  
  <pre><code>&lt;example package&gt;
  
  Added package 'postal.1.2.2' to folder 'd:\a\1\s\source\SolutionFolder\packages'
  
  &lt;loads more packages&gt;
  
  Installed:
      190 package(s) to packages.config projects
  </code></pre>
  
  <p>When the build task runs on the solution it fails with the following error on the first project it encounters:</p>
  
  <pre><code>[warning]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): 
  Warning MSB3245: Could not resolve this reference. Could not locate the assembly "postal, Version=1.2.14706.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
  ...
  Considered "d:\a\1\s\source\SolutionFolder\packages\postal.1.2.2\lib\postal.dll", but it didn't exist.
  </code></pre>
  
  <p>The same error occurs for each package dependency. It looks like the package restore task restores packages to here:</p>
  
  <pre><code>d:\a\1\s\source\SolutionFolder\packages\
  </code></pre>
  
  <p>And according to the build log it is looking for them here in the hierarchical package folder structure e.g:</p>
  
  <pre><code>d:\a\1\s\source\SolutionFolder\packages\&lt;package&gt;\&lt;lib&gt;\&lt;dll&gt;
  </code></pre>
  
  <p>I've tried a number of things including removing the <code>restoreDirectory</code> parameter from the restore task, running the MSBuild command locally (it works) and stripping out some of the packages however I'm still seeing the same build errors.</p>
  
  <p>Some of the project files also contain hintpaths; for example in the format:</p>
  
  <pre><code>  &lt;ItemGroup&gt;
      &lt;Reference Include="&lt;some package&gt;"&gt;
        &lt;HintPath&gt;..\packages\&lt;package&gt;\lib\&lt;dll&gt;&lt;/HintPath&gt;
      &lt;/Reference&gt;
  </code></pre>
  
  <p>Would anyone have any insights? Thanks.</p>