无法在 VS17 和 VS15 上恢复 nuget 包

Unable to restore nuget packages on VS17 and VS15

这是我第一次使用 Microsoft Visual Studio 或 .NET Frameworks。

当我第一次尝试构建此解决方案 (https://github.com/QuantConnect/Lean) 时 - 我在各自的软件上尝试了该解决方案的两个版本(VS17 和 VS15) - 我收到以下错误(在最后列出) post 出于相关原因)。

从这些错误中,我发现 恢复 nuget 包时存在问题,但是 当我尝试 installing/reinstalling/updating 从包括 Nuget 包管理器控制台,我收到 错误,例如:

PM> Install-Package QLNet -Version 1.9.2 Attempting to gather dependency information for package 'QLNet.1.9.2' with respect to project 'QuantConnect.Lean.Launcher', targeting '.NETFramework,Version=v4.5.2' Attempting to resolve dependencies for package 'QLNet.1.9.2' with DependencyBehavior 'Lowest' Resolving actions to install package 'QLNet.1.9.2' Resolved actions to install package 'QLNet.1.9.2' Removed package 'QLNet.1.10.0' from 'packages.config' Successfully uninstalled 'QLNet.1.10.0' from QuantConnect.Lean.Launcher Package 'QLNet.1.9.2' already exists in folder 'C:\Users\Work\QuantConnect\Lean-master\packages' Install failed. Rolling back... Package 'QLNet.1.9.2' does not exist in project 'QuantConnect.Lean.Launcher' Package 'QLNet.1.10.0' already exists in folder 'C:\Users\Work\QuantConnect\Lean-master\packages' Added package 'QLNet.1.10.0' to 'packages.config' Install-Package : Failed to add reference to 'QLNet'. At line:1 char:1 + Install-Package QLNet -Version 1.9.2 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

PM> Update-Package -reinstall QLNet Attempting to gather dependency information for multiple packages with respect to project 'QuantConnect', targeting '.NETFramework,Version=v4.5.2' Gathering dependency information took 5,32 sec Attempting to resolve dependencies for multiple packages. Resolving dependency information took 0 ms Resolving actions install multiple packages Found package 'QLNet 1.9.2' in 'C:\Users\Work\QuantConnect\Lean-master\packages'. Install failed. Rolling back... Executing nuget actions took 3,73 sec Update-Package : End of Central Directory record could not be found. At line:1 char:1 + Update-Package -reinstall QLNet + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Update-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

我也从这个页面下载并执行了 nuget.exe - recommended latest v4.4.1VS 2015 VSIX - latest v3.6.0https://www.nuget.org/downloads,但没有任何改变。

我该怎么办?

(This is what I get when I try building the solution:

>  1>------ Build started: Project: QuantConnect, Configuration: Debug Any CPU ------
>     1>C:\Program Files (x86)\MSBuild.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5):
> warning MSB3245: Could not resolve this reference. Could not locate
> the assembly "QLNet, Version=1.9.2.0, Culture=neutral,
> processorArchitecture=MSIL". Check to make sure the assembly exists on
> disk. If this reference is required by your code, you may get
> compilation errors.
> 
> 
> 1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\ConstantQLDividendYieldEstimator.cs(23,7,23,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\ConstantQLRiskFreeRateEstimator.cs(24,7,24,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\ConstantQLUnderlyingVolatilityEstimator.cs(24,7,24,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\IQLDividendYieldEstimator.cs(18,7,18,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\IQLRiskFreeRateEstimator.cs(18,7,18,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\IQLUnderlyingVolatilityEstimator.cs(18,7,18,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\OptionPriceModels.cs(21,7,21,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\QLOptionPriceModel.cs(20,7,20,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\TradingCalendar.cs(7,7,7,12):
> error CS0246: The type or namespace name 'QLNet' could not be found
> (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\OptionPriceModels.cs(25,46,25,76):
> error CS0246: The type or namespace name
> 'GeneralizedBlackScholesProcess' could not be found (are you missing a
> using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\OptionPriceModels.cs(25,78,25,92):
> error CS0246: The type or namespace name 'IPricingEngine' could not be
> found (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\QLOptionPriceModel.cs(26,46,26,76):
> error CS0246: The type or namespace name
> 'GeneralizedBlackScholesProcess' could not be found (are you missing a
> using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\QLOptionPriceModel.cs(26,78,26,92):
> error CS0246: The type or namespace name 'IPricingEngine' could not be
> found (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\QLOptionPriceModel.cs(25,36,25,66):
> error CS0246: The type or namespace name
> 'GeneralizedBlackScholesProcess' could not be found (are you missing a
> using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\QLOptionPriceModel.cs(25,68,25,82):
> error CS0246: The type or namespace name 'IPricingEngine' could not be
> found (are you missing a using directive or an assembly reference?)
>     1>C:\Users\Work\QuantConnect\Lean-master\Common\Securities\Option\QLOptionPriceModel.cs(232,46,232,59): error CS0246: The type or namespace name 'VanillaOption' could not be
> found (are you missing a using directive or an assembly reference?)
>     2>------ Build started: Project: QuantConnect.Indicators, Configuration: Debug Any CPU ------
>     3>------ Build started: Project: QuantConnect.Compression, Configuration: Debug Any CPU ------
>     4>------ Build started: Project: QuantConnect.Queues, Configuration: Debug Any CPU ------
>     5>------ Build started: Project: QuantConnect.Messaging, Configuration: Debug Any CPU ------
>     6>------ Build started: Project: QuantConnect.Api, Configuration: Debug Any CPU ------
>     2>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     7>------ Build started: Project: QuantConnect.Algorithm, Configuration: Debug Any CPU ------
>     7>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     7>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Indicators\bin\Debug\QuantConnect.Indicators.dll'
> could not be found
>     8>------ Build started: Project: QuantConnect.AlgorithmFactory, Configuration: Debug Any CPU ------
>     9>------ Build started: Project: QuantConnect.Algorithm.CSharp, Configuration: Debug Any CPU ------
>     10>------ Skipped Build: Project: QuantConnect.Algorithm.FSharp, Configuration: Debug Any CPU ------
>     10>Project not selected to build for this solution configuration 
>     11>------ Skipped Build: Project: QuantConnect.Algorithm.Python, Configuration: Debug Any CPU ------
>     11>Project not selected to build for this solution configuration 
>     8>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     8>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     3>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     12>------ Build started: Project: QuantConnect.Brokerages, Configuration: Debug Any CPU ------
>     4>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     6>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     13>------ Build started: Project: QuantConnect.VisualStudio15Plugin, Configuration: Debug Any CPU ------
>     5>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     12>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     12>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Compression\bin\Debug\QuantConnect.Compression.dll'
> could not be found
>     9>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     9>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm.Framework\bin\Debug\QuantConnect.Algorithm.Framework.dll'
> could not be found
>     9>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     9>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Indicators\bin\Debug\QuantConnect.Indicators.dll'
> could not be found
>     14>------ Build started: Project: QuantConnect.Lean.Engine, Configuration: Debug Any CPU ------
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm.CSharp\bin\Debug\QuantConnect.Algorithm.CSharp.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\AlgorithmFactory\bin\Debug\QuantConnect.AlgorithmFactory.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Api\bin\Debug\QuantConnect.Api.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Brokerages\bin\Debug\QuantConnect.Brokerages.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Compression\bin\Debug\QuantConnect.Compression.dll'
> could not be found
>     14>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Indicators\bin\Debug\QuantConnect.Indicators.dll'
> could not be found
>     15>------ Build started: Project: QuantConnect.ToolBox, Configuration: Debug Any CPU ------
>     16>------ Build started: Project: QuantConnect.Views, Configuration: Release Any CPU ------
>     17>------ Build started: Project: QuantConnect.Jupyter, Configuration: Debug Any CPU ------
>     15>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Brokerages\bin\Debug\QuantConnect.Brokerages.dll'
> could not be found
>     15>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     15>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Compression\bin\Debug\QuantConnect.Compression.dll'
> could not be found
>     15>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Engine\bin\Debug\QuantConnect.Lean.Engine.dll'
> could not be found
>     18>------ Build started: Project: QuantConnect.Lean.Launcher, Configuration: Debug Any CPU ------
>     13>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Api\bin\Debug\QuantConnect.Api.dll'
> could not be found
>     13>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm.CSharp\bin\Debug\QuantConnect.Algorithm.CSharp.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\AlgorithmFactory\bin\Debug\QuantConnect.AlgorithmFactory.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Api\bin\Debug\QuantConnect.Api.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Brokerages\bin\Debug\QuantConnect.Brokerages.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Compression\bin\Debug\QuantConnect.Compression.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Indicators\bin\Debug\QuantConnect.Indicators.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Engine\bin\Debug\QuantConnect.Lean.Engine.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Messaging\bin\Debug\QuantConnect.Messaging.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Queues\bin\Debug\QuantConnect.Queues.dll'
> could not be found
>     18>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\ToolBox\bin\Debug\QuantConnect.ToolBox.exe'
> could not be found
>     19>------ Build started: Project: QuantConnect.Tests, Configuration: Debug Any CPU ------
>     17>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     17>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Api\bin\Debug\QuantConnect.Api.dll'
> could not be found
>     17>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     17>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Indicators\bin\Debug\QuantConnect.Indicators.dll'
> could not be found
>     17>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Engine\bin\Debug\QuantConnect.Lean.Engine.dll'
> could not be found
>     17>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Queues\bin\Debug\QuantConnect.Queues.dll'
> could not be found
>     16>C:\Program Files (x86)\MSBuild.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5):
> warning MSB3270: There was a mismatch between the processor
> architecture of the project being built "MSIL" and the processor
> architecture of the reference "Geckofx-Core, Version=45.0.6.0,
> Culture=neutral, PublicKeyToken=3209ac31600d1857,
> processorArchitecture=x86", "x86". This mismatch may cause runtime
> failures. Please consider changing the targeted processor architecture
> of your project through the Configuration Manager so as to align the
> processor architectures between your project and references, or take a
> dependency on references with a processor architecture that matches
> the targeted processor architecture of your project.
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm.CSharp\bin\Debug\QuantConnect.Algorithm.CSharp.dll'
> could not be found
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Api\bin\Debug\QuantConnect.Api.dll'
> could not be found
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Engine\bin\Debug\QuantConnect.Lean.Engine.dll'
> could not be found
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Messaging\bin\Debug\QuantConnect.Messaging.dll'
> could not be found
>     16>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Queues\bin\Debug\QuantConnect.Queues.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm.CSharp\bin\Debug\QuantConnect.Algorithm.CSharp.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Algorithm\bin\Debug\QuantConnect.Algorithm.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\AlgorithmFactory\bin\Debug\QuantConnect.AlgorithmFactory.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Api\bin\Debug\QuantConnect.Api.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Brokerages\bin\Debug\QuantConnect.Brokerages.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Common\bin\Debug\QuantConnect.Common.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Compression\bin\Debug\QuantConnect.Compression.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Indicators\bin\Debug\QuantConnect.Indicators.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Engine\bin\Debug\QuantConnect.Lean.Engine.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Launcher\bin\Debug\QuantConnect.Lean.Launcher.exe'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Messaging\bin\Debug\QuantConnect.Messaging.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\Queues\bin\Debug\QuantConnect.Queues.dll'
> could not be found
>     19>CSC : error CS0006: Metadata file 'C:\Users\Work\QuantConnect\Lean-master\ToolBox\bin\Debug\QuantConnect.ToolBox.exe'
> could not be found
>     ========== Build: 0 succeeded, 17 failed, 2 up-to-date, 2 skipped ==========
> 
> 

)

Unable to restore nuget packages on VS17 and VS15

您应该在构建解决方案之前恢复 nuget 包。

一般我们在分享解决方案给别人的时候会忽略packages文件夹。因此,在您下载该解决方案后,您会发现文件夹 :C:\Users\Work\QuantConnect\Lean-master\packages 丢失了。

您应该右键单击解决方案,select 恢复 NuGet 包。恢复完成后,您可以构建没有错误的解决方案:

您可以检查该文件夹以确认包是否已恢复。

对于你的问题,我建议你可以删除packages文件夹,然后通过select "Restore NuGet Packages".

恢复包

顺便说一句,包恢复主要通过工具 > 选项 > NuGet 包管理器 在 Visual Studio:

中启用

有关详细信息,请参阅 Package Restore