Is there a way to install a NuGet package without all of its dependencies? - visual-studio

In a Visual Studio 2015 C# project, is there any way to selectively install the components of a NuGet package? (Aside from manually adding references)
Background:
I have been using the Microsoft.CodeAnalysis.CSharp package recently. This package contains several libraries that I need:
Microsoft.CodeAnalysis
Microsoft.CodeAnalysis.CSharp
It also installs many libraries that these are dependent on. For the features I am using, I only need these two:
System.Collections.Immutable
System.Reflection.Metadata
But it also installs many more libraries that I never need:
System.AppContext
System.ComponentModel.Composition
System.Console
System.Diagnostics.FileVersionInfo
System.Diagnostics.StackTrace
System.IO.FileSystem
System.IO.FileSystem.Primatives
System.Numerics
System.Security.Cryptography.Algorithms
System.Security.Cryptography.Encoding
System.Security.Cryptography.Primitives
System.Security.Cryptography.X509Certificates
System.Text.Encoding.CodePages
System.Threading.Thread
System.Xml
System.Xml.Linq
System.Xml.XmlDocument
System.Xml.XPath
Systen.Xml.XPath.XDocument
Is there someway I can check the boxes of the libraries I want when installing the package?

According to the docs , there only -IgnoreDependencies command could help us ignore all dependencies. We could not ignore part of dependencies.
But you could implement your requirement with -IgnoreDependencies, please refer to following steps:
Install the Microsoft.CodeAnalysis.CSharp package without any dependence:
Install-Package Microsoft.CodeAnalysis.CSharp -IgnoreDependencies
Install the dependence package Microsoft.CodeAnalysis. Common package without any dependence:
Install-Package Microsoft.CodeAnalysis.Common -IgnoreDependencies
Install the dependence package System.Collections.Immutable and System.Reflection.Metadata package:
Install-Package System.Collections.Immutable
Install-Package System.Reflection.Metadata
If you do not need to use the dependences of “System.Collections.Immutable”and “System.Reflection.Metadata”, you can also use the same option to ignore dependences.

Related

VisualStudio nuget: Unable to resolve dependency 'Microsoft.Graph.Auth'

When attempting to install a package that has a dependency to Microsoft.Graph.Auth, the nuget package manager in VisualStudio errors with this message:
Unable to resolve dependency 'Microsoft.Graph.Auth'. Source(s) used: 'nuget.org'
No other information is provided.
I can successfully install the Microsoft package manually, however.
The package that depends on the Microsoft package has this in its .nuspec, so as far as I can tell, it should work:
<dependency id="Microsoft.Graph.Auth" version="1.0.0-preview.7" />
I can find it by checking Include prerelease option.
As Per the doc Microsoft.Graph.Auth is deprecated and no longer maintained , either you can try by suggested alternative package Azure.Identity or try by installing via the NuGet package manager console.
NuGet\Install-Package Microsoft.Graph.Auth -Version 1.0.0-preview.7
Thanks

Nuget Visual Studio 2022 control dependency version

Whenever I try to install any package from Nuget through Visual Studio 2022 - be it the GUI or package manager console, I can't seem to find a way to get the highest dependency version.
For example: if I add latest version 1.0.152 protobuf-net.Grpc to my project it has a dependency on Grpc.Core.Api >= 2.36.1. The current version for Grpc.Core.Api is 2.46.3...
In the GUI under options I have no option to control dependency version what so ever it seems like the Install-Package cmdlet doesn't obey -DependencyVersion Highest:
Install-Package protobuf-net.Grpc -DependencyVersion Highest
Installing NuGet package protobuf-net.Grpc 1.0.152.
Committing restore...
Successfully installed 'Grpc.Core.Api 2.36.1'
Successfully installed 'Microsoft.NETCore.Platforms 2.1.0'
Successfully installed 'protobuf-net 2.4.6'
Successfully installed 'protobuf-net.Grpc 1.0.152'
Successfully installed 'System.Memory 4.5.3'
Successfully installed 'System.Private.ServiceModel 4.5.3'
Successfully installed 'System.Reflection.DispatchProxy 4.5.0'
Successfully installed 'System.Security.Principal.Windows 4.5.0'
Successfully installed 'System.ServiceModel.Primitives 4.5.3'
How can I force Nuget to install the highest dependencies version?
According to your description here are some suggestion:
First check your project type “-DependencyVersion Highest” only used in packages.config format.
You can see the project type support about two package management formats: Projects.config and PackageReference.
Someone posted a similar issue on github, see the issue here. Hope this help you.
If you want to use “Grpc.Core.Api 2.46.3 “, you can try to delete the bin and obj folder and then go to Tools>Options>Nuget Package Manager>General>Clear All Nuget Caches.
Then you can install Grpc.Core.Api 2.46.3 package before install protobuf-net.Grpc 1.0.152

How to use a more recent version of a NuGet package for dependent packages in .NET Core 3.1?

I have a NuGet package that references Newtonsoft.Json v 12.0.2. I can't access the source to that NuGet package. (Technically, NuGet Package Explorer stats that it's really >= 12.0.2 )
If I wish for that package to leverage Newtonsoft.Json v 12.0.3, is it as simple as me "installing" v 12.0.3 into my project and all dependants (and their children, etc) which are using v 12.0.2 will now be magically using my installed 12.0.3 version?
Or does each dependency only use the version explicitly defined in their package?
What is this called? explicit referencing?
Other Info: This is for .NET Core 3.1
For the new sdk project, when you install a nuget package, it will install its lowest dependencies on your project and if you want to use the higher version, you only need to install the updated dependency nuget package separately and then it will update all the dependencies to the updated version.
And it will update all dependencies of your project to that version. Note that it will not act on a single nuget package but all.
These two nuget packages used Newtonsoft.Json 12.0.2 dependency
And if I install Newtonsoft.Json 12.0.3 nuget package separately:
They all used Newtonsoft.Json 12.0.3 and it proves that they are Shared rather than using a separate version.

Xamarin : Could not install package Parse 1.7.0

I am currently working on a cross-platform app with Xamarin and I am trying to use the NuGet package Parse 1.7.0, but when I try to install the package via NuGet on Visual Studio 2015, I get this error :
Could not install package 'Parse 1.7.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Is it to understand the Parse official package is not compatible with Xamarin ? If so, is there a way to make it compatible ?
Thanks in advance !
If you look inside the nupkg of this package:
https://www.nuget.org/packages/parse
You will find a lib folder with the following targets available. Thus you are trying to target Profile259, but there is no definition in the Parse NuGet package for this. That is why it fails. You must install against one of these targets instead.
Thus if you installed this individually into MonoAndroid or Xamarin.iOS10, it work install just fine (Xamarin.Android and Xamarin.iOS projects respectfully).
Had the same, just remove the Silverlight platform from your targets and it should work

Why can't I install Ninject 3.2.2 if my project targets MonoAndroid,Version=v5.1?

When installing Ninject I get this log from the Output in VS2015:
Attempting to gather dependencies information for package 'Ninject.3.2.2' with respect to project 'ProjectPhoenix.Droid', targeting 'MonoAndroid,Version=v5.1'
Attempting to resolve dependencies for package 'Ninject.3.2.2' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Ninject.3.2.2'
Resolved actions to install package 'Ninject.3.2.2'
Attempting to gather dependencies information for package 'Ninject.3.2.2' with respect to project 'ProjectPhoenix.iOS', targeting 'Xamarin.iOS,Version=v1.0'
Attempting to resolve dependencies for package 'Ninject.3.2.2' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Ninject.3.2.2'
Resolved actions to install package 'Ninject.3.2.2'
For adding package 'Ninject.3.2.2' to project 'ProjectPhoenix.Droid' that targets 'monoandroid51'.
Install failed. Rolling back...
Package 'Ninject 3.2.2.0' does not exist in project 'ProjectPhoenix.Droid'
Could not install package 'Ninject 3.2.2'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v5.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
========== Finished ==========
I'm working on Xamarin and the same project runs great on Xamarin Studio and other instances of Visual Studio 2015, so I know this is a problem not with the code but with my configuration.
I believe what you're asking is answered here in this other SO question:
How come there's no IKernel implementation in Ninject.Portable
Ninject needs platform specific code to work in each Xamarin Platform, so, for a Xamarin project I would suggest you use the Ninject.Portable NuGet package instead of the plain Ninject one. You also need to install the NuGet in Droid, iOS, Tests and UITests projects to be able to compile all the Solution.
Best Regards

Resources