Teamcity failing to install packages via nuget - c#

SOLVED - PLEASE SEE COMMENT
I have a project on team city that is failing to install the required packages.
This has has worked for over a year but this week all builds started failing.
my development process is as follows:
We use github and develop locally using visual studio. We have a windows teamcity agent that does our compiling, and a teamcity server that automatically runs builds.
I get this Error on a build:
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(902, 9): error MSB3073: The command "nuget install C:\BuildAgent\work\MyProject\MyLibaries\Gelf4Net\Gelf4net\packages.config -o C:\BuildAgent\work\MyProject\MyLibaries\Gelf4Net\Gelf4net\Packages" exited with code 1.
In my packages.config i have the following packages i need to install:
package id="log4net" version="1.2.11"
package id="Newtonsoft.Json" version="4.5.10"
package id="RabbitMQ.Client" version="2.8.7"
I have read through many topics on the net and have tried the following:
removed all package folder from teamcity nuget (force new packages to be downloaded)
updated nuget to latest version (2.5)
re added all the references to the project and pushed
re added the project to teamcity
enabled and disabled nuget on teamcity
added the new nuget 2.5 to teamcity
If I run "nuget install C:\BuildAgent\work\MyProject\MyLibaries\Gelf4Net\Gelf4net\packages.config -o C:\BuildAgent\work\MyProject\MyLibaries\Gelf4Net\Gelf4net\Packages" on the build agent it works and installs the packages.
The projects build and run locally.
Please any suggestions or help is appreciated

I have found the issue, our projects incude many other projects and unless the packages in each project are on the same version, teamcity will fail to build

Related

How do i build an executable that contain depencies?

Visual Studio 2017 is not including dependencies such as NuGet packages, when i build it via the standard option (Build > Publish).
I have a command line project that is dependent on Nuget Packages. The packages are among other Selenium. When i publish the build it gives an error, because Seleium depencies are not present.
I have only tried to publish it in the standard way.
My questions is how i can publish/build the project, so that the Nuget packages are embedded in the executable.
Thanks in advance guys. I hope you can help me.

MSBuild fails on Unit Test Project (.NET Core) after NuGet Restore

ISSUE
The Visual Studio Build task in a Visual Studio Team Services build for a solution that contains a default ASP.NET MVC website and a default Unit Test Project is failing to find references. This task runs after a NuGet Restore that should install these references, but even though the NuGet Restore task succeeds, the references are not installed on the server running this build.
Visual Studio Team Services Logs
The error logs have been uploaded to This Github Repository
Attempted Fixes
In an effort to ensure that the packages are properly referenced by the project, all of the NuGet packages were reinstalled from Package Manager using the following command:
PM> Update-Package --reinstall
This only caused MSBuild to not find Microsoft.Net.Compilers.props in both the projects. So in an attempt to correct this, the version of Microsoft.Net.Compilers.props in the project was dropped to version 2.3.2. However, this only brought back the original errors where the MSTest.TestAdapter.props and Microsoft.Net.Compilers.props references could not be found.
Try it with these tasks (works fine for me with the sample solution you shared):
NuGet Tool Installer (Version of NuGet.exe to install: 4.3.0)
NuGet restore (Choose 2.* version)
Visual Studio Build (Visual Studio Version: Latest)
Queue build with the agent that has VS2017 installed.

TeamCity already has a dependency defined for

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

Nuget Restore via build server "unable to find version"

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

NuGet Restoration Never Works on Build Server

I have a pretty simple application with some NuGet references and it works fine locally. I have not committed the packages folder of course, just the config. When I have TeamCity build the solution, I originally got the error that I needed to enable Nuget Package Restore so I did.
Now when I build I get the message
The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568.
Makes sense, but I get this error no matter how many times I build it. It continually fails. Am I missing something here?
Run the NuGet package restore before you build the solution.
Team City should have a NuGet Installer step which will restore the NuGet packages. Add this to your build steps before the compilation of the solution.
You an also do this yourself with a build step which runs:
NuGet.exe restore YourSolution.sln
However Team City's built in NuGet build step allows you to configure other things, such as private NuGet repository urls, easier than creating your own build step from scratch.

Categories

Resources