How can I keep nuget from updating dependencies? - nuget

I'm attempting to install a nuget package which has incorrectly specified one of it's dependencies. Common.Logging.Log4Net requires log4net = 1.2.10 however the nuget package specifies log4net >= 1.2.10. Even if I manually install the older version of log4net, nuget upgrades log4net to 1.2.11 when I install Common.Logging.Log4Net. How can I get nuget to bypass dependency resolution or at least prefer installed packages of a sufficient version?

In order to bypass dependency resolution you can use the -IgnoreDependencies option:
Install-Package -IgnoreDependencies ThePackageName
You should be able to lock the package to a specific version by hand-editing the packages.config and setting the allowedVersions attribute to indicate the version span you want to allow.
<package id="Common.Logging.Log4Net" version="1.2.10"
allowedVersions="[1.2,1.2.10]" />
Note that his will however not upgrade the version of the package at all even when explicitly updating the package.
See the nuget versioning documentation for more info on versioning.

Related

Installing Nuget Gets Dependencies Only

I have a .NET Framework 4.5 project. I'm trying to install Microsoft.NET.Test.Sdk. This should be possible as per https://www.nuget.org/packages/Microsoft.NET.Test.Sdk/
I ran the following command, but get the dependencies only. I tried installing via the Nuget Package Manager too. Finally... I see the package inside my packages.config file, but don't see it in my references. Any suggestions?
Install-Package Microsoft.NET.Test.Sdk -Version 15.7.0
I ended up using Microsoft.VisualStudio.TestTools.UnitTesting.

Nuget Package Manager for single project fails to load after adding RingCentralSDK

I'm on VS 2015, targeting .net 4.5.2, my "Nuget Package Manager for Visual Studio" in Extensions and Updates shows 3.4.4.1321.
I added all dependencies of RingCentralSDK package separately:
Microsoft.Bcl
Microsoft.Bcl.Async
Microsoft.Bcl.Build
Microsoft.Net.Http
Newtonsoft.Json
Portable.BouncyCastle-Signed
PubnubPCL
Then I right click on my project, pick "Manage Nuget Packages...", the tab opens, in the "Installed" subtab I can see the 7 packages.
Now, I install the RingCentralSDK package. My output is fine:
Attempting to gather dependency information for package 'RingCentralSDK.1.0.0' with respect to project 'MyProj', targeting '.NETFramework,Version=v4.5.2'
Attempting to resolve dependencies for package 'RingCentralSDK.1.0.0' with DependencyBehavior 'Lowest'
Resolving actions to install package 'RingCentralSDK.1.0.0'
Resolved actions to install package 'RingCentralSDK.1.0.0'
Adding package 'RingCentralSDK.1.0.0' to folder 'C:\code\packages'
Added package 'RingCentralSDK.1.0.0' to folder 'C:\code\packages'
Added package 'RingCentralSDK.1.0.0' to 'packages.config'
Successfully installed 'RingCentralSDK 1.0.0' to MyProj
========== Finished ==========
Now, I check again the Manage Nuget Packages for this specific project, and instead of seeing the list of packages, I get a yellow band:
Error occured Show erros in output Dismiss
And in the "Package Manager" output, the error is:
ZIP archive contains unsupported data structures.
In my packages folder, the folder "RingCentralSDK.1.0.0" seems ok, but then I don't anything about nuget packages format.
I cannot uninstall RingCentral via the package manager as it's not showing, not any other one, which is really annoying. I had an error when trying to do it via the command line. I reverted my changes (or remove the line in packages.config for my project), and the Nuget Package Manager tab works fine again. This is also affecting the "Managet Nuget Packages for Solution".
What can I do to fix this?
Fixed in RingCentralSDK 1.0.1-alpha1
It turns out that the NuGet package created on Mac is not compatible with Visual Studio NuGet GUI tool.
You can install the latest version by
Install-Package RingCentralSDK -Pre
Or if you prefer GUI:
Update:
For projects which already have 1.0.0 version installed, how to upgrade?
Today I did some testing and I came to the following conclusion:
New project will have no problem with 1.0.1 version or later
For old project which have 1.0.0 installed. You need to follow the following steps:
UnInstall RingCentralSDK 1.0.0
Close VS
Delete packages folder in your project
Delete packages folder in ~/.nuget/
Launch VS
Install RingCentralSDK 1.0.1
I need to do the above because nuget has cache. If I don't do it the problem just persists. I don't know the exactly reason but the above steps did work for me.

Nuget not reinstalling packages

I have modified the target .net framework to use 4.5 from 4.0. I got a message from nuget that packages need to re-installed so ran Update-Package -Reinstall -ProjectName https://localhost/SomeWebProject/. As nuget was executing, it spitted out yellow warning signs that looked like this:
Skipped reinstalling package 'NLog 3.1.0.0' in project 'SomeWebProject' because the package does not exist in the package source.
Why aren't my packages being reinstalled? I went into my packages folder and verified NLog 3.1.0.0 exist!
Turns out the solution is hiding in plain sight.
All we have to do is set the Package Source in the Package Manager Console window. (Credits to Matt Ward for pointing it out.)
Or you may run the following NuGet Package Management command:
'Update-Package -reinstall'
This command will reinstall all your solutions NuGet packages without updating the version(s) of existing packages.

Build a C# project fails in nuget restore package Microsoft.ApplicationInsights

I have this Azure Notification Hubs Sample
and it fails because
The 'Microsoft.ApplicationInsights 0.12.0-build17386' package requires
NuGet client version '2.8.50313' or above, but the current NuGet
version is '2.8.1.0'. The command "eval nuget restore
src/NotificationHubSample.sln" failed. Retrying, 2 of 3.
why?
It is a problem with the Microsoft.ApplicationInsights NuGet package. In its .nuspec file it has the following:
<metadata minClientVersion="2.8.50313">
NuGet will check the minClientVersion defined by a NuGet package against its product version to see if they are compatible.
The minClientVersion used in the Microsoft.ApplicationInsights NuGet package seems to be using the NuGet assembly file version and not the NuGet product version. So NuGet restore or install will always fail, at least until a newer version of NuGet is released. The latest NuGet released has a product version of 2.8.3.
Note that I am ignoring NuGet 3.0 which currently has a CTP release. So this NuGet package would work with NuGet 3.0 so maybe the creators of the Microsoft.ApplicationInsights NuGet package have only tested it with that version.
So your options are:
Report the problem to the owners of the Microsoft.ApplicationInsights NuGet package and wait for them to fix it.
Use NuGet.exe 3.0 to run the package restore with Travis.
Use a different version of the Microsoft.ApplicationInsights NuGet package which does not have this minClientVersion restriction.

Nuget package dependencies. Does it work the way it should?

RavenDb latest version is installed as a nuget package. It references Newtonsoft.Json 4.0.2.
I'm trying to install TweetSharp. I get this log:
M> Install-Package TweetSharp
Attempting to resolve dependency 'Hammock (≥ 1.2.3)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 4.0.1)'.
Successfully installed 'Hammock 1.2.6'.
Successfully installed 'Newtonsoft.Json 4.0.3'.
Successfully installed 'TweetSharp 2.0.8'.
Install failed. Rolling back...
Install-Package : Updating 'Newtonsoft.Json 4.0.2' to 'Newtonsoft.Json 4.0.3'
failed. Unable to find a version of 'RavenDB-Embedded' that is compatible with
'Newtonsoft.Json 4.0.3'.
As you can see, even if TweetSharp just needs 'Newtonsoft.Json (≥ 4.0.1)', nuget wants to install version 4.0.3 which can not work with RavenDb.
I tried to install previous versions of TweetSharp but it does not change anything.
Any way to circumvent this?
Sounds like a possible bug in NuGet. Please log an issue in the NuGet bug tracker: http://nuget.codeplex.com/workitem/list/basic
If TweetSharp is fine with NewtonSoft.Json 4.0.2, then the install should not have failed. In your bug, can you post the exact versions that caused this problem. For example:
List of installed packages with exact version installed.
List of dependencies for each package and the specific version range they specify.
And the exact version of TweetSharp you're trying to install. That'll help us look at the issue more quickly. Thanks!
My guess is we have some default logic that tries to upgrade packages to the latest bug fix release. In this case, we tried that, but it causes another dependency to fail. In that case, we should have known that and not tried to upgrade.
This is down to the semantic versioning that NuGet has had since (I think) 1.6. It's explained in more detail here but the basic idea is that if your dependency hasn't updated either the major or the minor revision number then they'll assume that it's a bugfix and not a breaking change.
So in this case the decision to install 4.0.3 instead of 4.0.1 was made.
You can run install-package with -ignoredependencies I would have thought that if you'd had 4.0.2 installed it wouldn't try to update you (because 4.0.2 satisfies the dependency).