I have a VS solution and as part of a TeamCity Build, we restore packages from both a private NuGet feed (myget) and the public feed (nuget.org). Most packages restore fine, but it hangs on the ones below for WebApi and Mono.Security. This is all working locally in Visual Studio.
[restore] NuGet command: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\953bd084b49f7d88\DataFinch.Web.sln -Source https://www.myget.org/F/datafinch/auth/<hidden>/api/v2 -Source https://api.nuget.org/v3/index.json
[11:41:35][restore] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script473789219385667038.cmd
[11:41:35][restore] in directory: C:\TeamCity\buildAgent\work\953bd084b49f7d88
[11:41:35][restore] JetBrains TeamCity NuGet Runner 8.0.37059.9
[11:41:35][restore] Registered additional extensions from paths: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\plugins-2.8
[11:41:35][restore] Starting NuGet.exe 2.8.50926.602 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Client'.
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Core'.
[11:41:43][restore] Unable to find version '3.2.3.0' of package 'Mono.Security'.
[11:41:43][restore] Unable to find version '6.0.4' of package 'Newtonsoft.Json'.
[11:41:43][restore] Process exited with code 1
Teamcity config:
Try using https://www.nuget.org/api/v2instead of https://api.nuget.org/v3/index.json per the nuget docs: https://docs.nuget.org/consume/Command-Line-Reference.
The reason why the build failed, was an old version of nuget.exe. I finally solved this problem by downloading the latest version and put this executable in the Program Files x86 folder. Then I created a new system variabele to point to this executable. After that I add a NuGetInstaller package in my TFS Build Definition to let me configure TFS using this new NuGet.exe.
This link helped me to let TFS use this new NuGet version
I followed this: https://blogs.msdn.microsoft.com/tfssetup/2017/04/18/tfs-2017-update-1-nuget-restore-task-always-fails-trying-to-find-packages-even-though-they-exist-on-the-feed/
I had tried 3.3 and got this error:
Restoring NuGet package Microsoft.AspNet.WebPages.3.2.3.
WARNING: Unable to find version '3.5.0.2' of package 'Antlr'.
I downloaded the latest NuGet 4.3.0.4406 and set the Custom path to NuGet and that failed as well.
Surprisingly when I switched to 3.5 it worked.
If you are really stuck, run the command in a Command Line Prompt and it will work:
C:\Program Files (x86)\NuGet\nuget.exe restore -NonInteractive E:\agentXYZPool\_work\1\s\xyz.sln
I ran into this problem with one of our build slaves leveraging TFS and Visual Studio.
The way I fixed it was, I opened the solution that wasn't compiling in Visual Studio, right-clicked on the SLN and selected "Enable Restore NuGet Packages"
That prompts a dialog box that you have to accept. After you've done that, you might be good to go. Right-click on the SLN again and run "Restore NuGet Packages", and if that operation succeeds, you're golden.
There's probably some setting you can adjust programmatically when setting up your slave environments, but that's one direct way to fix this kind of problem.
According to THIS current document as of this writing from MS, the proper url is: https://api.nuget.org/v3/index.json
So I went about to fix the issue because I assumed it had nothing to do with the URL. I did 2 things, not sure which it was that resolved the issue but I'll post both here in case it helps someone.
Within TFS2018 and within my build step for the installation of Nuget I specified version 4.9.3 (the reason I chose 4.9.3 because I noticed by looking at detailed log of VS that during my build it was using this version) and chose to always download the latest version.
Second thing I did was I removed a Nuget.Config file from my project that was left over from something I was testing. Then I re-commited my changes to TFS
After I did both of the above steps the rest of my build started working.
Using an old version of Visual Studio's Nuget
Visual Studio has C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\Nuget.exe. Jenkins was using that to nuget restore
Updated Nuget in program files,
C:\Program Files (x86)\NuGet> ./nuget.exe update -self
Pointed Jenkins at that new Nuget path and 🔥cooking with gas🔥
SET PATH=%PATH%;C:\Program Files (x86)\NuGet
nuget restore SolutionName.sln
Related
In the company I work, inside every solution we have one folder packages, which contains all dll dependencies. This folder is not in repository with the rest of the solution.
Every time I build one project, all files inside folder packages are restored and any missing dlls appear again. This happens in the beginning of the build, no matter if the build succeeds of fails. Even if the project has no dll dependencies, any missing dlls in packages are restored.
I suspect it is a setting in msbuild but I cannot find it. Does anyone know where it might be or if there is a place with msbuild *.targets files?
thanks for any help
This is because Visual Studio restores packages defined in the packages.config files.
You can control this behaviour in Visual Studio in options:
From the MS Docs regarding regarding Nuget:
MSBuild: use the msbuild -t:restore command, which restores packages
packages listed in the project file (PackageReference only). Available
only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual
Studio 2017. nuget restore and dotnet restore both use this command
for applicable projects.
Further down, there's quite a bit about enabling/disabling and modifying this behavior in a variety of ways.
Allow NuGet to download missing packages: controls all forms of
package restore by changing the packageRestore/enabled setting in the
NuGet.Config file as shown below (%AppData%\NuGet\NuGet.Config on
Windows, ~/.nuget/NuGet/NuGet.Config on Mac/Linux). In Visual Studio,
this setting allows the Restore NuGet Packages command on the
solution's context menu to work.
Appearing to be more to your issue:
Automatically check for missing packages during build in Visual
Studio: controls automatic restore by changing the
packageRestore/automatic setting in the NuGet.Config file as shown
below (%AppData%\NuGet\NuGet.Config on Windows,
~/.nuget/NuGet/NuGet.Config on Mac/Linux). When this option is set,
running a build from Visual Studio automatically restores any missing
packages. The option does not affect builds run from the command line
using MSBuild.
I am using Visual Studio 2017 and pull the source code from TFS server, then build the solution, I got the following error:
Microsoft.Common.CurrentVersion.targets (3863,5): Error MSB3113: The
file "SqlServerTypes \ x64 \ SqlServerSpatial140.dll" was not found.
Then I found this dll file comes from the nuget package sqlserver.types, as I know, Visual Studio will restore the nuget packages when we build the solution.
Why I still have this issue?
File was not found after nuget restore
When you download the nuget package Microsoft.SqlServer.Types from the nuget.org and open it with nuget package explorer:
You will find the sqlserver.types nuget package not only includes .dll from .net framework, but also has native binaries files. These files are designed with x64 and x84, they could not added to lib folder directly. So the package owner adds them to project as content. However, these dll files is setting to ignore by default for TFS, you need to add them manually.
Of course, you can also use the command line Update-Package <package_name> –reinstall to reinstall this nuget package, but this requires you to execute this command every time after you pull the code from the TFS server. Add this native binaries to the source control will Will reduce these unnecessary troubles.
Hope this helps.
You can try this:
Update-Package <package_name> –reinstall
I'm getting 3 types of errors when trying to build the project from a specific branch.
In the others branchs it works properly.
These are the problems:
1- The command ""D:\Web\Hom\.nuget\NuGet.exe" install "D:\Web\Hom\ServiceClient\packages.config" -source "" -NonInteractive -RequireConsent -solutionDir "D:\Web\Hom\ "" exited with code 1.
2- Unable to find version '1.0.4632' of package 'AppFabric'.
3- NuGet Package restore failed for project Web.ServiceClient: Unable to find version '1.0.4632' of package 'AppFabric'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'AppFabric.1.0.4632' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.https://api.nuget.org/v3/index.json: Package 'AppFabric.1.0.4632' is not found on source 'https://api.nuget.org/v3/index.json'
NuGet will restore packages to the packages directory based on the packages.config file. Please compare the packages.config in specific branch with others branches, the package “AppFabric” element exists in the specific branch. So the NuGet would download the “AppFabric” package from the package Sources before project compiled.
According to the error messages, the “AppFabric” package has not been published to the NuGet server, NuGet could not download it from the NuGet server. You can according to the following methods to resolve this problem:
(1) Download the “AppFabric” package, Creating a local NuGet repository, add this package to the repository.
(2) Download the “AppFabric” package, publish this package to the NuGet server before the project compiled.
Note that: You need to use "Update-Package -reinstall" command in Package Manager Console force reinstall the package references and content files into project after restore successfully.
Let me start out by saying, I am completely new to TeamCity.
The project I am building was built with VS 2013, so I have my Nuget version set to 2.8.6. I saw in some other posts that this issue normally happens from not running the latest nuget package, but this is the latest compatible package I can use.
The project builds completely fine in Visual studio but the build fails every time in TC at this line. The 30 or 40 packages prior to this install successfully
[Exec] C:\TeamCity\buildAgent\work\52c756fe2f1d3d74\OPIS\.nuget\NuGet.targets(100, 9): 'JSNLog' already has a dependency defined for 'Newtonsoft.Json'.[08:09:38]
[Exec] C:\TeamCity\buildAgent\work\52c756fe2f1d3d74\OPIS\.nuget\NuGet.targets(100, 9): error MSB3073: The command ""C:\TeamCity\buildAgent\work\52c756fe2f1d3d74\OPIS\.nuget\NuGet.exe" install "C:\TeamCity\buildAgent\work\52c756fe2f1d3d74\OPIS\OPIS\packages.config" -source "" -NonInteractive -solutionDir "C:\TeamCity\buildAgent\work\52c756fe2f1d3d74\OPIS\ "" exited with code 1.
I have tried reinstalling JSNlog and Newtonsoft.Json in my VS project, cleaning all files within TC and still, removing the project from TC as a whole and redoing the build steps and I get the same error
I have solved same problem by upgrading Nuget in TeamCity.
You have to log as system administrator.
Go to panel Administration
Go to Integrations->Nuget-> Tab Nuget.exe
Button Fetch Nuget -> choose a version superior than current and set as default
Check in your build configuration if step nuget pack uses new version of nuget, and run!
Mine was 2.8.0, now is 3.4.3
I have a few solution level NuGet packages attached to a Visual Studio 2010 solution via .nuget/packages.config.
These packages each contain a Init.ps1 file. I'm trying to pre-install the packages via commandline or script on my CI server. Running nuget install .nuget\packages.config -o packages pulls the packages down into the packages folder. But it does not run the Init.ps1 scripts.
If I attempt and msbuild call on the solution file, it fails because required files installed by the package Init.ps1 files are not in place yet.
If I open up the solution in Visual Studio, the packages run Init.ps1.
How can I get the Init.ps1 files to fire along with the package install from a commandline/script without having to open Visual Studio?
The best you can do is fake it. Run the scripts by hand by invoking PowerShell. But there might be problems with them. The $project argument passed to init.ps1 is a DTE object, and you can't make it available without a full copy of VS.