Reputation: 1681
Using MsTest.TestAdapter version 1.4.0 as an example, I am trying to understand how NuGet resolves the dependencies for this package during install.
I am not interested in the details of what version of each package will be resolved, but where this information is located.
If I execute the following command in an arbitrary folder:
nuget install -source https://api.nuget.org/v3/index.json MSTest.TestAdapter -version 1.4.0
You will see that at the end of the install there will be 50 packages installed.
Assuming these are dependencies resolved by NuGet, where does it get this dependency tree? I looked at the package information (nuspec, props, targets) and could not find any clue.
Any ideas?
Upvotes: 0
Views: 136
Reputation: 76880
If by "explicity states" you mean the dependencies tag on the nuget specification, then I must say I am targeting .NET 4.5 and not .NETCoreApp1.0. How this would work?
Just as Lex said "The package itself explicitly states what are the direct dependencies", according to the MSTest.TestAdapter, we could to know the dependency tree of this package is like:
<dependencies>
<group targetFramework=".NETCoreApp1.0">
<dependency id="NETStandard.Library" version="1.6.1" />
<dependency id="System.Diagnostics.TextWriterTraceListener" version="4.3.0" />
</group>
</dependencies>
But if you execute the install command without option -Framework
, nuget will restore all the dependencies of this package. That the reason why there will be 50 packages installed.
If you are targeting .NET 4.5, you should use the option -Framework
to specify the Framework, like:
nuget install -source https://api.nuget.org/v3/index.json MSTest.TestAdapter -version 1.4.0 -Framework 4.5
In this case, nuget only get the dependencies for .NET 4.5. Check the document install command (NuGet CLI) for some more details.
Note:
The install command does not modify a project file or packages.config; in this way it's similar to restore in that it only adds packages to disk but does not change a project's dependencies.
To add a dependency, either add a package through the Package Manager UI or Console in Visual Studio, or modify packages.config and then run either install or restore.
Hope this helps.
Upvotes: 1