使用 nuget.exe 命令行安装依赖项 [英] using nuget.exe commandline to install dependency

查看:42
本文介绍了使用 nuget.exe 命令行安装依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 CI 构建管道中使用 nuget.exe(版本 2.5)来安装一个依赖于另一个包的包.

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

我有以下 nuspec 文件.

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>

和 B 类似.我用来安装的packages.config文件是:

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>

然后我运行以下命令:

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

我得到输出:

Successfully installed 'A 1.0.0.1'.

但不要安装我的依赖项 B.

but do not get my dependency B installed.

但是如果将 B 单独放在 packages.config 文件中,我会同时安装 A 和 B.我希望在我们安装 A 时安装 B,因为它是 A 的依赖项.我们没有将 dll 放在 GAC 中(所以我相信依赖项解析应该不是问题).此外,我打开了 A.nupkg 并检查了那里是否列出了依赖项.此外,当我在 Visual Studio 编辑器中安装 A 时,B 也被安装.(这是应该发生的).

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).

仅安装 A 时如何使用 nuget.exe 并安装依赖项 B(仅将 A 放在 packages.config 中).

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

谢谢

推荐答案

这是不可能的.packages.config 文件的行为是设计使然.只安装在packages.config 中指定的东西,而不是它们的依赖项.还必须明确指定所有依赖项.

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.

如果您查看源代码,您将看到 nuget.exe 安装了packages.config (http://nuget.codeplex.com/SourceControl/latest#src/CommandLine/Commands/InstallCommand.cs) 使用 PackageExtractor.InstallPackage (http://nuget.codeplex.com/SourceControl/latest#src/CommandLine/Common/PackageExtractor.cs):

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));
    }

注意对 ignoreDependencies: true

这篇关于使用 nuget.exe 命令行安装依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆