NuGet 安装 - 包 'EntityFramework.6.2.0' 已存在于文件夹中 - csproj 引用另一个项目包文件夹

NuGet Install - Package 'EntityFramework.6.2.0' already exists in folder - csproj references another projects packages folder

NuGet Install 没有安装或更新包,而是引用了另一个项目包文件夹。无论如何我可以停下来吗?当我使用 Manage NuGet Packages for Solution...Manage NuGet Packages... 并通过 Package Manager Console.

时发生
Install-Package EntityFramework -Version 6.2.0

https://www.nuget.org/packages/EntityFramework/

包管理器的输出:

Attempting to gather dependency information for package 'EntityFramework.6.2.0' with respect to project 'Project\Project.Domain.Business', targeting '.NETFramework,Version=v4.6.1'
Gathering dependency information took 21,42 ms
Attempting to resolve dependencies for package 'EntityFramework.6.2.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'EntityFramework.6.2.0'
Resolved actions to install package 'EntityFramework.6.2.0'


Attempting to gather dependency information for package 'EntityFramework.6.2.0' with respect to project 'Project\Project.ServiceComponents', targeting '.NETFramework,Version=v4.6.1'
Gathering dependency information took 18,45 ms
Attempting to resolve dependencies for package 'EntityFramework.6.2.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'EntityFramework.6.2.0'
Resolved actions to install package 'EntityFramework.6.2.0'
Removed package 'EntityFramework.6.1.3' from 'packages.config'
Successfully uninstalled 'EntityFramework.6.1.3' from Project.Clients.Admin
Package 'EntityFramework.6.2.0' already exists in folder 'C:\Users\oscar\Documents\Solution\environment-setup\packages'
Added package 'EntityFramework.6.2.0' to 'packages.config'
Executing script file 'C:\Users\oscar\Documents\Solution\environment-setup\packages\EntityFramework.6.2.0\tools\install.ps1'...

上一个.csproj:

<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>

.csproj 之后:

<HintPath>..\..\..\environment-setup\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>

看到这个 。如果您使用 packages.config 格式管理不同解决方案中项目的 nuget 包,这是已知行为。

要解决这个问题,您需要为解决方案范围定义自定义 nuget.config 文件。

<configuration>
  <config>
    <add key="repositoryPath" value="C:\Packages" />
  </config>
</configuration>

或者您可以将 packages.config 格式转换为 PackageReference 来解决问题。

(在 VS2019 中,右键单击 packages.config 文件并选择从 Packages.config 迁移到 PackageReference,目前此选项不适用于 .net fx web 应用程序,请参阅 this)