Ben Rubin
Ben Rubin

Reputation: 7341

Build error for missing Nuget package even though "nuget restore" ran

I'm trying to set up a Jenkins server to build an ASP Core project. I have my Jenkins project configured to use the MSBuild from my installed Visual Studio 2017. I downloaded Nuget v5.3.1 and added it to my PATH.

My Jenkins project is configured with two build steps. The first step is to run nuget restore. The second step is "Build a Visual Studio project or solution using MSBuild" on my solution file (AspCore.sln)

When I try to build the project in Jenkins, I get the following error. However, it appears that all of the Nuget packages were downloaded successfully.

C:\Program Files\dotnet\sdk\2.1.509\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.VisualStudio.Web.CodeGeneration, version 2.1.9 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. [C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj]

Here's the full Jenkins build log.

Started by user Ben Rubin
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment
using credential 633afff1-dea9-4aab-a44a-0a4d127afd1b
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url [email protected]:Toreth/AspCoreTest.git # timeout=10
Fetching upstream changes from [email protected]:Toreth/AspCoreTest.git
 > git.exe --version # timeout=10
using GIT_SSH to set credentials 
 > git.exe fetch --tags --force --progress -- [email protected]:Toreth/AspCoreTest.git +refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision c0e95238b58d6648c51fac0a817fa5d3e60ce615 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f c0e95238b58d6648c51fac0a817fa5d3e60ce615
Commit message: "Initial commit."
 > git.exe rev-list --no-walk c0e95238b58d6648c51fac0a817fa5d3e60ce615 # timeout=10
[Windows Service Deployment] $ cmd /c call C:\Windows\TEMP\jenkins4544019004588734090.bat

C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment>nuget restore 
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin'.
Restoring packages for C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj...
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.design/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.design/index.json 45ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.design/2.1.9/microsoft.visualstudio.web.codegeneration.design.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.design/2.1.9/microsoft.visualstudio.web.codegeneration.design.2.1.9.nupkg 31ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegenerators.mvc/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegenerators.mvc/index.json 42ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegenerators.mvc/2.1.9/microsoft.visualstudio.web.codegenerators.mvc.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegenerators.mvc/2.1.9/microsoft.visualstudio.web.codegenerators.mvc.2.1.9.nupkg 30ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration/index.json 44ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration/2.1.9/microsoft.visualstudio.web.codegeneration.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration/2.1.9/microsoft.visualstudio.web.codegeneration.2.1.9.nupkg 29ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.entityframeworkcore/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.entityframeworkcore/index.json 58ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.entityframeworkcore/2.1.9/microsoft.visualstudio.web.codegeneration.entityframeworkcore.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.entityframeworkcore/2.1.9/microsoft.visualstudio.web.codegeneration.entityframeworkcore.2.1.9.nupkg 29ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.core/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.core/index.json 41ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.core/2.1.9/microsoft.visualstudio.web.codegeneration.core.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.core/2.1.9/microsoft.visualstudio.web.codegeneration.core.2.1.9.nupkg 30ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.templating/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.templating/index.json 42ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.templating/2.1.9/microsoft.visualstudio.web.codegeneration.templating.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.templating/2.1.9/microsoft.visualstudio.web.codegeneration.templating.2.1.9.nupkg 29ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.utils/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.utils/index.json 60ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.utils/2.1.9/microsoft.visualstudio.web.codegeneration.utils.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.utils/2.1.9/microsoft.visualstudio.web.codegeneration.utils.2.1.9.nupkg 30ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.contracts/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.contracts/index.json 61ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.contracts/2.1.9/microsoft.visualstudio.web.codegeneration.contracts.2.1.9.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.contracts/2.1.9/microsoft.visualstudio.web.codegeneration.contracts.2.1.9.nupkg 32ms
Installing Microsoft.VisualStudio.Web.CodeGeneration.Contracts 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGeneration.Utils 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGeneration.Templating 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGeneration.Core 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGeneration 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGenerators.Mvc 2.1.9.
Installing Microsoft.VisualStudio.Web.CodeGeneration.Design 2.1.9.
Committing restore...
Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\obj\AspCore.csproj.nuget.g.props.
Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\obj\AspCore.csproj.nuget.g.targets.
Writing assets file to disk. Path: C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\obj\project.assets.json
Restore completed in 3.73 sec for C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj.

NuGet Config files used:
    C:\Windows\system32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
    https://api.nuget.org/v3/index.json

Installed:
    8 package(s) to C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj

C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment>exit 0 
Path To MSBuild.exe: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe
Executing the command cmd.exe /C " chcp 1252 & "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" AspCore.sln " && exit %%ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment
[Windows Service Deployment] $ cmd.exe /C " chcp 1252 & "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" AspCore.sln " && exit %%ERRORLEVEL%%
Active code page: 1252
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 10/27/2019 4:54:18 PM.
Project "C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Any CPU".
Project "C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore.sln" (1) is building "C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj" (2) on node 1 (default targets).
C:\Program Files\dotnet\sdk\2.1.509\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.VisualStudio.Web.CodeGeneration, version 2.1.9 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. [C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj]
Done Building Project "C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj" (default targets) -- FAILED.
Done Building Project "C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore.sln" (default targets) -- FAILED.

Build FAILED.

"C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore.sln" (default target) (1) ->
"C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj" (default target) (2) ->
(ResolvePackageAssets target) -> 
  C:\Program Files\dotnet\sdk\2.1.509\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.VisualStudio.Web.CodeGeneration, version 2.1.9 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. [C:\Program Files (x86)\Jenkins\workspace\Windows Service Deployment\AspCore\AspCore.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.44
Build step 'Build a Visual Studio project or solution using MSBuild' marked build as failure
Finished: FAILURE    

Upvotes: 1

Views: 5988

Answers (1)

Paco
Paco

Reputation: 11

Please take a look at this solution, it worked for me:

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

so you just need to call this build command defining the nuget path in the jenkinsfile:

sh 'dotnet build --packages ./.nuget/packages'

Upvotes: 1

Related Questions