Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using nuget.exe commandline to install dependency

Tags:

nuget

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

like image 341
user1746773 Avatar asked Jun 19 '13 09:06

user1746773


People also ask

How do I run NuGet exe?

To use any command, open a command window or bash shell, then run nuget followed by the command and appropriate options, such as nuget help pack (to view help on the pack command). This documentation reflects the latest version of the NuGet CLI.

Does NuGet automatically install dependencies?

Install NuGet packages without dependenciesBy default, when installing NuGet packages, corresponding package dependencies will also be installed in your project. To avoid the installation of dependent packages, choose the Ignore Dependencies option in the Dependency behavior drop-down in NuGet Package Manager.


1 Answers

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

like image 126
ferventcoder Avatar answered Sep 28 '22 05:09

ferventcoder