如何解决 NuGet.exe 命令行无法安装 xunit 2.1.0 的问题?

How can I resolve NuGet.exe command line being unable to install xunit 2.1.0?

在Visual Studio 2013 中创建一个全新的项目,使用update 5 和NuGet Package Manager 2.8.60610.756 可以完美安装xunit 2.1.0

------- Installing...xunit 2.1.0 -------
Attempting to resolve dependency 'xunit.core (= 2.1.0)'.
Attempting to resolve dependency 'xunit.extensibility.core (= 2.1.0)'.
Attempting to resolve dependency 'xunit.abstractions (= 2.0.0)'.
Attempting to resolve dependency 'xunit.extensibility.execution (= 2.1.0)'.
Attempting to resolve dependency 'xunit.assert (= 2.1.0)'.
Installing 'xunit.abstractions 2.0.0'.
Added file 'xunit.abstractions.dll' to folder 'xunit.abstractions.2.0.0\lib\net35'.
Added file 'xunit.abstractions.xml' to folder 'xunit.abstractions.2.0.0\lib\net35'.
Added file 'xunit.abstractions.dll' to folder 'xunit.abstractions.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS'.
Added file 'xunit.abstractions.xml' to folder 'xunit.abstractions.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS'.
Added file 'xunit.abstractions.2.0.0.nupkg' to folder 'xunit.abstractions.2.0.0'.
Successfully installed 'xunit.abstractions 2.0.0'.
Installing 'xunit.extensibility.core 2.1.0'.
Added file 'xunit.core.dll' to folder 'xunit.extensibility.core.2.1.0\lib\dotnet'.
Added file 'xunit.core.dll.tdnet' to folder 'xunit.extensibility.core.2.1.0\lib\dotnet'.
Added file 'xunit.core.pdb' to folder 'xunit.extensibility.core.2.1.0\lib\dotnet'.
Added file 'xunit.core.xml' to folder 'xunit.extensibility.core.2.1.0\lib\dotnet'.
Added file 'xunit.runner.tdnet.dll' to folder 'xunit.extensibility.core.2.1.0\lib\dotnet'.
Added file 'xunit.runner.utility.desktop.dll' to folder 'xunit.extensibility.core.2.1.0\lib\dotnet'.
Added file 'xunit.core.dll' to folder 'xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.core.dll.tdnet' to folder 'xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.core.pdb' to folder 'xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.core.xml' to folder 'xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.runner.tdnet.dll' to folder 'xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.runner.utility.desktop.dll' to folder 'xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.extensibility.core.2.1.0.nupkg' to folder 'xunit.extensibility.core.2.1.0'.
Successfully installed 'xunit.extensibility.core 2.1.0'.
Installing 'xunit.extensibility.execution 2.1.0'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\dnx451'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\dnx451'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\dnx451'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\dotnet'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\dotnet'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\dotnet'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\monoandroid'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\monoandroid'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\monoandroid'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\monotouch'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\monotouch'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\monotouch'.
Added file 'xunit.execution.desktop.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\net45'.
Added file 'xunit.execution.desktop.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\net45'.
Added file 'xunit.execution.desktop.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\net45'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\win8'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\win8'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\win8'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\wp8'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\wp8'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\wp8'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\wpa81'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\wpa81'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\wpa81'.
Added file 'xunit.execution.dotnet.dll' to folder 'xunit.extensibility.execution.2.1.0\lib\xamarinios'.
Added file 'xunit.execution.dotnet.pdb' to folder 'xunit.extensibility.execution.2.1.0\lib\xamarinios'.
Added file 'xunit.execution.dotnet.xml' to folder 'xunit.extensibility.execution.2.1.0\lib\xamarinios'.
Added file 'xunit.extensibility.execution.2.1.0.nupkg' to folder 'xunit.extensibility.execution.2.1.0'.
Successfully installed 'xunit.extensibility.execution 2.1.0'.
Installing 'xunit.core 2.1.0'.
Added file '_._' to folder 'xunit.core.2.1.0\build\dnx451'.
Added file '_._' to folder 'xunit.core.2.1.0\build\monoandroid'.
Added file '_._' to folder 'xunit.core.2.1.0\build\monotouch'.
Added file '_._' to folder 'xunit.core.2.1.0\build\net45'.
Added file 'xunit.core.props' to folder 'xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81'.
Added file '_._' to folder 'xunit.core.2.1.0\build\win8'.
Added file 'xunit.core.props' to folder 'xunit.core.2.1.0\build\win81'.
Added file '_._' to folder 'xunit.core.2.1.0\build\wp8'.
Added file 'xunit.core.props' to folder 'xunit.core.2.1.0\build\wpa81'.
Added file '_._' to folder 'xunit.core.2.1.0\build\xamarinios'.
Added file 'xunit.execution.desktop.dll' to folder 'xunit.core.2.1.0\build\_desktop'.
Added file 'xunit.core.2.1.0.nupkg' to folder 'xunit.core.2.1.0'.
Successfully installed 'xunit.core 2.1.0'.
Installing 'xunit.assert 2.1.0'.
Added file 'xunit.assert.dll' to folder 'xunit.assert.2.1.0\lib\dotnet'.
Added file 'xunit.assert.pdb' to folder 'xunit.assert.2.1.0\lib\dotnet'.
Added file 'xunit.assert.xml' to folder 'xunit.assert.2.1.0\lib\dotnet'.
Added file 'xunit.assert.dll' to folder 'xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.assert.pdb' to folder 'xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.assert.xml' to folder 'xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81'.
Added file 'xunit.assert.2.1.0.nupkg' to folder 'xunit.assert.2.1.0'.
Successfully installed 'xunit.assert 2.1.0'.
Installing 'xunit 2.1.0'.
Added file 'xunit.2.1.0.nupkg' to folder 'xunit.2.1.0'.
Successfully installed 'xunit 2.1.0'.
Adding 'xunit.abstractions 2.0.0' to ClassLibrary1.
For adding package 'xunit.abstractions 2.0.0' to project 'ClassLibrary1' that targets 'net45',
>> Assembly references are being added from 'lib\net35'
Added reference 'xunit.abstractions' to project 'ClassLibrary1'
Added file 'packages.config'.
Added file 'packages.config' to project 'ClassLibrary1'
Successfully added 'xunit.abstractions 2.0.0' to ClassLibrary1.
Adding 'xunit.extensibility.core 2.1.0' to ClassLibrary1.
For adding package 'xunit.extensibility.core 2.1.0' to project 'ClassLibrary1' that targets 'net45',
>> Assembly references are being added from 'lib\portable-net45+win8+wp8+wpa81'
Added reference 'xunit.core' to project 'ClassLibrary1'
Added file 'packages.config'.
Successfully added 'xunit.extensibility.core 2.1.0' to ClassLibrary1.
Adding 'xunit.extensibility.execution 2.1.0' to ClassLibrary1.
For adding package 'xunit.extensibility.execution 2.1.0' to project 'ClassLibrary1' that targets 'net45',
>> Assembly references are being added from 'lib\net45'
Added reference 'xunit.execution.desktop' to project 'ClassLibrary1'
Added file 'packages.config'.
Successfully added 'xunit.extensibility.execution 2.1.0' to ClassLibrary1.
Adding 'xunit.core 2.1.0' to ClassLibrary1.
For adding package 'xunit.core 2.1.0' to project 'ClassLibrary1' that targets 'net45',
>> Build files are being added from 'build\portable-net45+win8+wp8+wpa81'
Added file 'packages.config'.
Successfully added 'xunit.core 2.1.0' to ClassLibrary1.
Adding 'xunit.assert 2.1.0' to ClassLibrary1.
For adding package 'xunit.assert 2.1.0' to project 'ClassLibrary1' that targets 'net45',
>> Assembly references are being added from 'lib\portable-net45+win8+wp8+wpa81'
Added reference 'xunit.assert' to project 'ClassLibrary1'
Added file 'packages.config'.
Successfully added 'xunit.assert 2.1.0' to ClassLibrary1.
Adding 'xunit 2.1.0' to ClassLibrary1.
Added file 'packages.config'.
Successfully added 'xunit 2.1.0' to ClassLibrary1.
==============================

使用最新的 NuGet 命令行 exe (2.8.60717.93) 执行相同的安装步骤失败,说明它需要 NuGet 3.0...

C:\development\tools\nuget> nuget update -self
Checking for updates from https://www.nuget.org/api/v2/.
Currently running NuGet.exe 2.8.6.
NuGet.exe is up to date.
C:\development\tools\nuget> nuget
NuGet Version: 2.8.60717.93
usage: NuGet <command> [args] [options]
Type 'NuGet help <command>' for help on a specific command.

Available commands:

 config      Gets or sets NuGet config values.

 delete      Deletes a package from the server.

 help (?)    Displays general help information and help information about other commands
             .

 install     Installs a package using the specified sources. If no sources are specified
             , all sources defined in the NuGet configuration file are used. If the conf
             iguration file specifies no sources, uses the default NuGet feed.

 list        Displays a list of packages from a given source. If no sources are specifie
             d, all sources defined in %AppData%\NuGet\NuGet.config are used. If NuGet.c
             onfig specifies no sources, uses the default NuGet feed.

 pack        Creates a NuGet package based on the specified nuspec or project file.

 push        Pushes a package to the server and publishes it.
             NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.
             config, then loading any nuget.config or .nuget\nuget.config starting from
             root of drive and ending in current directory.

 restore     Restores NuGet packages.

 setApiKey   Saves an API key for a given server URL. When no URL is provided API key is
             saved for the NuGet gallery.

 sources     Provides the ability to manage list of sources located in %AppData%\NuGet\N
             uGet.config

 spec        Generates a nuspec for a new package. If this command is run in the same fo
             lder as a project file (.csproj, .vbproj, .fsproj), it will create a tokeni
             zed nuspec file.

 update      Update packages to latest available versions. This command also updates NuG
             et.exe itself.

For more information, visit http://docs.nuget.org/docs/reference/command-line-reference
C:\development\tools\nuget> nuget install xunit -version 2.1.0
Attempting to resolve dependency 'xunit.core (= 2.1.0)'.
Attempting to resolve dependency 'xunit.extensibility.core (= 2.1.0)'.
Attempting to resolve dependency 'xunit.abstractions (= 2.0.0)'.
Attempting to resolve dependency 'xunit.extensibility.execution (= 2.1.0)'.
Attempting to resolve dependency 'System.Collections (= 4.0.0)'.
Attempting to resolve dependency 'System.Runtime (= 4.0.0)'.
Attempting to resolve dependency 'System.Diagnostics.Debug (= 4.0.0)'.
Attempting to resolve dependency 'System.Globalization (= 4.0.0)'.
Attempting to resolve dependency 'System.IO (= 4.0.0)'.
Attempting to resolve dependency 'System.Text.Encoding (= 4.0.0)'.
Attempting to resolve dependency 'System.Threading.Tasks (= 4.0.0)'.
Attempting to resolve dependency 'System.Linq (= 4.0.0)'.
The 'System.Linq 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60717.93'.
C:\development\tools\nuget>

Visual Studio 根本没有提到系统库,利用 VS2013 "Enable NuGet Package Restore" 也可用于恢复包及其依赖项,并且 运行 与 NuGet.exe 命令行

简短的回答是您无法阻止 NuGet.exe 版本 2 使用 nuget install xunit -version 2.1.0.

从命令行下载 xunit 2.1.0 失败

当您在 Visual Studio 中执行相同的操作时,下载的依赖项仅限于项目的目标框架支持的依赖项。

当您使用 nuget install xunit -version 2.1.0 时,没有项目,因此没有目标框架,因此所有依赖项都被认为是兼容的,因此将全部下载。对于 xunit 2.1.0,其依赖项之一是 System.Linq 4.0.0,它需要 NuGet 3.0.

您的解决方法是:

  1. 改用 packages.config 文件。 packages.config 文件将存储目标框架信息。
  2. 使用 NuGet.exe 版本 3。