user1746773
user1746773

Reputation: 171

using nuget.exe commandline to install dependency

I want to use nuget.exe (version 2.5) in my CI build pipeline to install a package which has dependency to another package.

I have following nuspec file.

<?xml version="1.0"?>
<package>
  <metadata>
    <id>A</id>
    <dependencies>
      <dependency id="B" version="1.0.0.1" />
    </dependencies>
  </metadata>
  <files>
    <file src="A.dll" target="lib" />
  </files>
</package>

and similar for B. and my packages.config file which I used to install is:

<packages>
  <package id="A" version="1.0.0.1" allowedVersions="[1,2)"/>
</packages>

and I run following command:

NuGet.exe install packages.config -ExcludeVersion -Outputdir libs -source http://get.nuget.mydomain

I get output:

Successfully installed 'A 1.0.0.1'.

but do not get my dependency B installed.

But if put B separately in packages.config file, I get both A and B getting installed. I expected B to be installed when we install A as it is a dependency of A. We do not put dlls in GAC (so I believe dependency resolution should not be a problem).Also I have opened A.nupkg and checked that is has dependency listed there. Also when I install A from with in visual studio editor B also gets installed.(which is what should happen).

How do I use nuget.exe and install dependency B when i install A only (put A only in packages.config).

thanks

Upvotes: 17

Views: 2931

Answers (1)

ferventcoder
ferventcoder

Reputation: 12561

This is not possible. The behavior of the packages.config file is by design. Only things specified in the packages.config are installed, not their dependencies. All dependencies must be explicitly specified as well.

If you look at the source code you will see that nuget.exe install packages.config (http://nuget.codeplex.com/SourceControl/latest#src/CommandLine/Commands/InstallCommand.cs) uses PackageExtractor.InstallPackage (http://nuget.codeplex.com/SourceControl/latest#src/CommandLine/Common/PackageExtractor.cs):

public static void InstallPackage(IPackageManager packageManager, IPackage package)
    {
        var uniqueToken = GenerateUniqueToken(packageManager, package.Id, package.Version);
        // Prerelease flag does not matter since we already have the package to install and we ignore dependencies.
        ExecuteLocked(uniqueToken, () => packageManager.InstallPackage(package, ignoreDependencies: true, allowPrereleaseVersions: true));
    }

Note the hard call to ignoreDependencies: true

Upvotes: 7

Related Questions