NuGet restore failed JetBrains Package - jenkins

When I build my .NET Solution in Jenkins and try to restore NuGet packages before the actual MSBuild step I'm getting this error:
C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Package JetBrains.Annotations, version 11.1.0 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. [PATHLENGHT = 86]
I'm using MSBuild 15 and NuGet Windows x86 Commandline nuget.exe v4.7.0
Any ideas?
Cheers

Since this was a .Net Standard Project, i need to add this command to make it a successful build:
/t:restore

Related

The NuGet Installer task used in TFS 2017 build definition fails to clear the global-packages folder with an error

We have a build definition in place created in TFS 2017, which builds a .net solution that has dependency on some of our NuGet packages, during compilation the solution restores the NuGet package from packages (global-packages) folder present at this path %userprofile%\.nuget\packages instead of downloading latest one from our internal feed.
I saw a command at this page to avoid using the global-packages folder, but when I added the nuget locals global-packages -clear argument in NuGet installer task, which is used to restore the nuget packages, the task failed with the below error saying unknown option -Clear.
The NuGet Version I am using is 3.5.0 in the task.
2019-09-05T09:27:18.8819742Z ##[section]Starting: NuGet restore $(build.sourcesdirectory)/IntelliSuiteService.sln
2019-09-05T09:27:18.8819742Z ==============================================================================
2019-09-05T09:27:18.8819742Z Task : NuGet Installer
2019-09-05T09:27:18.8819742Z Description : Installs or restores missing NuGet packages
2019-09-05T09:27:18.8819742Z Version : 0.2.31
2019-09-05T09:27:18.8819742Z Author : Microsoft Corporation
2019-09-05T09:27:18.8819742Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613747)
2019-09-05T09:27:18.8819742Z ==============================================================================
2019-09-05T09:27:19.4601187Z [command]C:\Windows\system32\chcp.com 65001
2019-09-05T09:27:19.4757465Z Active code page: 65001
2019-09-05T09:27:19.5069958Z Detected NuGet version 3.5.0.1938 / 3.5.0
2019-09-05T09:27:19.5226206Z SYSTEMVSSCONNECTION exists true
2019-09-05T09:27:19.5226206Z [command]F:\Builds\NextGen_Gated\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.31\node_modules\nuget-task-common\NuGet\3.5.0\NuGet.exe restore -NonInteractive F:\Builds\NextGen_Gated\2\s\SuiteService.sln -NoCache nuget locals global-packages -Clear
2019-09-05T09:27:20.1007732Z Unknown option: '-Clear'
2019-09-05T09:27:20.1163983Z ##[error]Error: F:\Builds\NextGen_Gated\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.31\node_modules\nuget-task-common\NuGet\3.5.0\NuGet.exe failed with return code: 1
2019-09-05T09:27:20.1163983Z ##[error]Packages failed to install
2019-09-05T09:27:20.1320334Z ##[section]Finishing: NuGet restore $(build.sourcesdirectory)/SuiteService.sln
You should run the command separately from the nuget restore command.
You can can log in to the agent machine and run it from the command line, or in the build add a command line or batch task that run the command.

Jenkins - Run a NuGet package restore to generate this file

When I build .NET Standard 2.0 Library on Jenkins build server
C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Assets file 'C:\Jenkins\workspace\<Project>\Sources\Library\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Jenkins\workspace\<Project>\Sources\Library\Library.csproj]
I got an error above in build log.
I searched about error and I found solution
However, when running:
dotnet restore <Solution Name>
the solution does not help me out when I clean my workspace before build starts.
Therefore, I insert command before MSBuild but I failed with
C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Package Microsoft.CodeAnalysis.CSharp.Workspaces, version 2.8.0 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:\Jenkins\workspace\<Project>\Sources\Web\Web.csproj]
According to Solution reference, maybe upgrade Nuget Package Installer could help me out. But I do not know how can I upgrade Nuget Package Installer by command line...
I had the same problem, getting the same error:
error : Package <package> 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. [<path>]
I was able to solve it using MSBuild /t:restore instead of dotnet restore.
See: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target
UPDATE: It's worth mentioning that problems in Jenkins are discussed in depth in this other answer.
The hint by #Mat didn't work for me: the /t:restore is currently not able to restore nuget packages for projects using package.config, as I mention here. What worked for me is the following:
call "%PROGRAMFILES(X86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
nuget restore CodeBinder.sln
MSBuild Solution.sln /p:Configuration=Release /p:Platform="Any CPU" /t:build /restore
pause
It basically requires to download the nuget CLI from official site[1], Windows x86 Commandline section. The switch /restore , as pointed here, fixed the partially completed Nuget restore error, similarly to MSBuild /t:restore, but it can be done in conjunction with /t:build.
[1] https://www.nuget.org/downloads

Nuget Restore in MS Build Step

In my asp.net web application, i have solution with 5 projects and nuget.org. In TFS Build Definition,
1) While building the whole solution in Visual Studio Build Task
Nuget packages getting restored.
2) While trying to generate executable files for individual projects in MS Build Task
If I select Restore Nuget packages, It's not finding nuget packages and step getting failed with message - "Process 'NuGet.exe' exited with code '1'."
I have tried many references online and none worked. Any suggestions on how to solve this?
Do i need to make any changes in the nuget.config file to support restoring
packages to individual projects.
Do not directly select Restore Nuget pacakges in MS build task configuration. This option is deprecated. To restore NuGet packages, add a NuGet Installer step before the build.
(Important) This option is deprecated. Make sure to clear this
checkbox and instead use the NuGet Installer build step.
Source Link: MSBuild
Besides, you could also build single project not the entire solution in Visual Studio Build task. Just select the project (.*proj) files instead of .sln file.
Unless you are building a customized MSBuild project file, then we recommend you use the MSBuild step instead of the Visual Studio Build step.
You could also try to build single project using Visual Studio Build task, see if the issue is still exists.
Same problem, downgraded to 4.4.1. it helped

Packaging nuget package on VSTS 'Newtonsoft.Json' already has a dependency defined for 'NETStandard.Library'

Packaging a build use Nuget Packager in VSTS and i get the error:
[error]'Newtonsoft.Json' already has a dependency defined for 'NETStandard.Library'.
Most of the hints that solves this involves updating nuget, but since I am building on Team Services I can't really do this.
It seems that the nuget used by nuget packager is not the latest. After testing locally with latest nuget.exe everything worked so I added a new powershell release step. This solution is appropriate for VSTS, for TFS where you have access to the server I recommend upgrading nuget.exe on the server itself:
This script downloads nuget.exe into the artifacts directory (and outputs the path to the nuget.exe so you can see where it is put.).
I then altered the Nuget Packager build step to use the freshly downloaded nuget.exe.
Had the same issue today.
Using your own build agent
If you are using your own build agents (rather than the hosted agent) you can manually update the version of NuGet to the latest version. In my case, this has resolved my problems.
e.g. C:\agent\externals\nuget\nuget.exe
Using the hosted agent
It's a bit messy but you could just upload the latest nuget.exe into the repo and set the NuGet Packager to use this.
To anyone getting this in 2018, Microsoft have created a new version of the NuGet task that fixes this issue. No need for powershell install steps.
Change the NuGet task version in your build step version to 2.*
This caused some breaking changes for me, that I resolved with the following advanced settings
Nuget Restore
Nuget Pack
Nuget push

Nuget Installer task fails in tfs 2017 builds

We are using Nuget Installer step that restores the missing nuget packages in TFS build, this step fails with the following error:
E:\Builds\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.29\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe restore -NonInteractive E:\Builds\test.sln
MSBuild auto-detection: using msbuild version '3.5' from 'C:\Windows\Microsoft.NET\Framework\v3.5'.
Error parsing solution file at E:\Builds\test.sln: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
Error: E:\Builds\Agent2017Update1_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.29\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe failed with return code: 1
Packages failed to install
The error message seems to be confusing as the file specified is present on build agent.
TFS build agent version:2.112.0
TFS version: TFS 2017 update 1
In the Advanced options change the version to 3.5 for NuGet. I've been having weird issues the last 2 weeks where 3.3 would do similar to what you are experiencing and switching to 3.5 works as expected.
Hope this works for you as well =D
This seems to be due to the fact that the msbuild.exe in your path (your build agent) is version 3.5. MSBuild 3.5 does not have two .dll's that nuget are attempting to load dynamically (Microsoft.Build.dll and Microsoft.Build.Framework.dll).
A solution to fix this issue, please make sure NuGet.exe uses MSBuild
4.0 or higher. This can be done by making sure MSBuild 4.0 or higher is the first to resolve in your path or by passing the -msbuildversion
option. For example, use MSBuild 14.0 (which shipped with Visual
Studio 2015).
nuget.exe pack MyProj.csproj -msbuildversion 14.0
More details please refer this similar issue nuget pack fails when MSBuild version resolved to MSBuild 3.5

Resources