无法在 .Net Framework 4.6 上安装 Microsoft.Extenstions.Logging Nuget 包,Visual Studio 2015

Cannot Install Microsoft.Extenstions.Logging Nuget Package, on .Net Framework 4.6, Visual Studio 2015

我正在尝试在我的 ASP.Net MVC 5 projecton,.Net 4.6,Visual Studio 2015 上安装 Nuget 包:Microsoft.Extenstions.Logging,并不断收到此错误:

Attempting to gather dependency information for package 'Microsoft.Extensions.Configuration.2.0.0' with respect to project 'ProjectName.web', targeting '.NETFramework,Version=v4.6.1' Gathering dependency information took 271.03 ms Attempting to resolve dependencies for package 'Microsoft.Extensions.Configuration.2.0.0' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'Microsoft.Extensions.Configuration.2.0.0' Resolved actions to install package 'Microsoft.Extensions.Configuration.2.0.0' Retrieving package 'Microsoft.Extensions.Configuration 2.0.0' from 'nuget.org'. GET https://api.nuget.org/v3-flatcontainer/microsoft.extensions.configuration/2.0.0/microsoft.extensions.configuration.2.0.0.nupkg OK https://api.nuget.org/v3-flatcontainer/microsoft.extensions.configuration/2.0.0/microsoft.extensions.configuration.2.0.0.nupkg 259ms Installing Microsoft.Extensions.Configuration 2.0.0. Install failed. Rolling back... Package 'Microsoft.Extensions.Configuration.2.0.0' does not exist in project 'ProjectName.web' Package 'Microsoft.Extensions.Configuration.2.0.0' does not exist in folder 'C:\Git\ProjectName\packages' Executing nuget actions took 1.27 sec Could not install package 'Microsoft.Extensions.Configuration 2.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. ========== Finished ========== Time Elapsed: 00:00:05.6980685

这是另一个 link 这个问题,在 Github 上:issue

但没有提供任何 solution/workaround 来解决这个问题...

事实证明,安装时需要注意两件事:Microsoft.Extensions.Logging(以及许多其他 Microsoft.Extensions.*)...

第一个问题是您需要 Nuget 版本 4.3.0 或更高版本才能安装此包。由于我使用的是 visual studio 2015,它带有较低版本的 Nuget,所以我必须安装:[https://dist.nuget.org/visualstudio-2015-vsix/v3.6.0/NuGet.Tools.vsix][1]

或者我可以升级到 Nuget 4.4.0 附带的 Visual Studio 2017。

我遇到的第二个问题是最初我的 .Net Framework 版本是 4.5,Microsoft.Extensions.Logging 依赖于 .NetStandard 2.0,因此,如果您使用的是 .Net Framework,则需要 4.6 版。 1 或更高。

就我而言,我安装了 VS 2017,将 Target Framework 更改为 .Net Framework 4.6.1,最后我可以安装 Nuget 包。

我使用了这种方法并且对我有用!

  1. 在 Visual Studio 中,导航到工具 > NuGet 包管理器 > 包管理器设置 > 常规
  2. 单击“清除所有 NuGet 缓存”
  3. 等待过程完成并单击“确定”

现在重试安装包,应该可以正常工作:)