CI Build on TeamCity Fails due to dependency on Microsoft.Bcl - c#

When I try and build my project in Teamcity (or in a clean repository on my machine), it fails with the error message
The schema version of 'Microsoft.Bcl' is incompatible with version 1.7.30402.9028 of NuGet. Please upgrade NuGet to the latest version from <nuget url>...
I've set my NuGet.Targets to restore packages, and not require user interactions to accept licenses. In addition both my local machine and the build server have the restore packages setting enabled (in the project/env variable as appropriate).
I'm aware of this issue http://blogs.msdn.com/b/dotnet/archive/2013/06/12/nuget-package-restore-issues.aspx. I've tried the second and third options suggested here, but without success.
Does anyone have any suggestions how to resolve this error?

Turns out the version of NuGet that is held in the .nuget folder of my solution was out of date. The version that Visual Studio uses had updated correctly, but the command line version didn't.
I followed the instructions described here Nuget versioning issue with package restore to resolve the problem.
In the solution directory run these commands:
cd .nuget
nuget.exe update -Self

Try updating the nuget that teamcity is using
If you are using version 8.x.x
Administration -> Nuget Settings -> Nuget Commandline -> (click fetch nuget) -> then choose the latest version and install it. Make sure "Set as Default" is checked.

Related

How to achieve full NuGet reinstall for dozens of solutions?

We have dozens of solutions in a repository and we're retargeting every project to net472 from net462. Currently our best bet is to open each and every solution in Visual Studio and execute the following command in the Package Manager Console.
Update-Package -Reinstall -IgnoreDependencies
As far as I'm aware, the PM console cannot be used outside Visual Studio, so this method of course is not very efficient, so what I was thinking about is using the nuget.exe tool for this. However at first glance I could not find any equivalent operation or argument set.
The documentation at this moment says the following
For all packages, delete the package folder, then run nuget install.
For a single package, delete the package folder and use nuget install
to reinstall the same one.
So based on this I tried to delete the packages folder and run nuget install for a project, so I expected it to do a re-install. However, while it installed the package indeed (to packages), it does not touch the packages.config (for retargeting).
Is anyone aware of any kind of possible way to automate this process?
How to achieve full NuGet reinstall using nuget.exe CLI?
That command cannot get what you want.
As far as I know, nuget install should be with packages.config file and it will not update the nuget framework version of packages.config file automatically.
So whenever you change the target framework version of your project, using that command will not update the target framework version of the nuget package.
So only update-package -reinstall command under Package Manager Console will update the target framework version of packages.config file.
And also Package Manager Console cannot access multiple solutions so you have to open each solution to run that command.
Although it may be possible to achieve your expectations with PowerShell scripts, but it is too complex so that it is easier to open each solution and then run the command.
As a suggestion,
1) open each solution on VS to run update-package -reinstall command.
2) And migrating from packages.config to PackageReference may be a good choice. In this case, the nuget packages will automatically adapt to the corresponding project target framework version.
Before doing this,you can make a backup of your project.
3) If these all do not meet your requirements, you could suggest a feature on our User Voice Forum to report your desire for automation. After that, you can share the link here and anyone who is interested in it will vote it so that it will get more attention from Microsoft.

Visual Studio NuGet Cannot Restore Packages

I have a large project that has about a dozen dependencies. I have tried to install them all but ran into an error from VS. I am using Visual Studio 2015
"An error occurred while trying to restore packages: Unable to find version '3.0.3.1' of package'Lucene.Net.Core'."
Now I have a solution which I can use that is by the same name as this package, but VS refuses to let me updates, remove, or change ANYTHING related to these packages and asks that I restore the packages. I am entirely lost here friends, what should I do?
P.S. the two sources I am using for my package sources are:
https://www.nuget.org/api/v2/
https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/
The same error occurs for Lucene.Net.Contrib, pstsdk.net, and various packages.
One thing to check for is if your project is built on a version of the NET framework that is less than or equal to the target framework the package has.
If your project is a NET 4.5 based project, but the nuget package has a NET 4.5.2... then the package manager will error out.
"An error occurred while trying to restore packages: Unable to find version '3.0.3.1' of package'Lucene.Net.Core'."
When I use the packages sources which you provided, I found that only two versions (4.8.0 & 4.9.0) of package"Lucene.Net.Core" not have the version '3.0.3.1'.
Pay Attention:
I noticed that the author of this package have updated this package at March 11, 2017(3/11/2017), and only release the version 4.8.0 & 4.9.0. So this must be the reason for NuGet restore failed.
Besides, you said:
I have a solution which I can use that is by the same name as this
package, but VS refuses to let me updates, remove, or change ANYTHING
related to these packages
If you want to remove those error packages, you can try to use below command to force uninstall those packages:
Uninstall-Package Lucene.Net.Core -Force
Or you can delete this package from the package folder and delete the package list from the package.config.
Then install the correct version of the packages.
Although I was not able to get any of the posted answers to work, I ended up removing the project entirely and reinstalling VS, my project, and its dependencies. This ended up working.
Another thing to check is that the package manager configuration settings in visual studio list the public nuget feed (and if the feed is enabled too).

new .net core visual studio 2017 project nuget restore in CI build definition

So currently, I am working on a .net core project in Visual Studio 2017. And I am also need to setup CI (Continuous Integration) in VSTS.
Here is my nuget restore step in my build definition
But my build is failing because it couldn't restore any packages. Here is the log of its. It said that "None of the projects in this solution specify any packages". I know that in VS2017 they changed the way nuget packages are being handled.
Anyone has an idea or experience about this?
2017-03-22T20:25:11.9517911Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2017-03-22T20:25:11.9674167Z Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
2017-03-22T20:25:11.9830425Z ##[section]Finishing: NuGet restore **/*.sln
I don't want to use dotnet restore because Microsoft said that
.NET Core's dotnet restore command doesn't currently support encrypted
credentials. To use VSTS NuGet feeds with dotnet restore, you'll need
to specify a Personal Access Token in plain text.
so I don't want to store my Personal Access Token.
https://www.visualstudio.com/en-us/docs/package/nuget/auth#net-core
You need to use NuGet 4.0.
Download it form the official NuGet site. https://dist.nuget.org/index.html
Put it in a folder on the machine where you have the build agent.
In the Advanced settings of the NuGet restore step set the NuGet version to Custom.
In the Path to NuGet.exe specify the path where you have put the NuGet.exe file. This is the path on the machine where the build agent is running. I tried with a relative path but was not able to get it working so in the end I have put an absolute path. This might be a problem for you if you have multiple agents with different paths so you might need to figure out how to correctly specify the relative path.
The Nuget restore task just includes Nuget.exe 3.3 and 3.5, so there isn’t the option of 4.0. You can check the files in [build agent folder]\tasks\NuGetInstaller\[version]\ node_modules\nuget-task-common\NuGet folder.
You can build a custom build/release task to include nuget.exe 4.0 and use this task instead. More information, you can refer to Add a build task.
On the other hand, you can add Nuget.exe to the source control, then map it to the build agent (Repository tab of build definition) and specify the path with built-in variable (e.g. $(build.sourcesdirectory))

TFS 2015 Automatically update packages from custom nuget repository on build

I am working on setting up repository at work. I would like to be able to force the TFS builds to use the latest version of each of our in house packages in a given solution without having to modify each project manually, instead of just using the default package restore behavior. I have seen some things online about using nuget.target to perform this but could not find supporting documents from nuget's website. I am open to just about any approach as long as the ending result is that my build server will ultimately us latest version of our packages automatically. We are using version 3.4.4 of nuget.
The fix was to as Adriano Repetti said which was to add a step to perform nuget update after nuget restore was on the build server using the cmd line directives.

'Portable.BouncyCastle' already has a dependency defined for 'System.Collections'

This error occurs on the Bamboo build server during a command that restores my solution's NuGet packages. I can bypass this error by disabling the package restore task; however, this is only a temporary fix. Is there any way I can check if the dependency exists while running the task? This error occurs before MSBUILD is running. I am using .NET 4.5
The already has a dependency defined for error when installing a NuGet package is due to a bug in older versions of NuGet.
You should look at updating NuGet on the build server or run your own build step that uses a version of NuGet that you download or deploy separately.
This issue is fixed if you use nuget version: 3.4.4+
https://dist.nuget.org/index.html
I would recommend using latest version

Categories