您的项目未引用“.NETFramework,Version=v4.5”框架。

Your project is not referencing the ".NETFramework,Version=v4.5" framework.

我使用的是 VS 2015。

Your project is not referencing the ".NETFramework,Version=4.5" framework. Add a reference to ".NETFramework,Version=4.5" in the "frameworks" section of your project.json, and then re-run NuGet restore.

我在添加到 MVC 层后不久就在我的数据访问层和业务逻辑层上收到此错误。直到那时一切都很好,但我不知道是什么触发了这个错误。这是我的 project.json:

{
  "version": "1.0.0-*",
  "description": "foo bar Class Library",
  "authors": [ "foo bar" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "frameworks": {
    "net451": { },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  }
}

这是我尝试过的:

  1. 将 "dotnet5.4" 替换为 "net451"(并删除),如 this answer.

结果是同样的错误。

  1. 将 "dotnet5.4" 替换为 "net45" 并保留 "net451"。这会导致新错误:

Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win":{} }' to your project.json and then re-run NuGet restore.

我尝试按照此错误建议进行操作并添加

"runtimes": {
    "win":  {}
  },

这给了我这个错误,我似乎无法过去:

Your project.json doesn't list 'win' as a targeted runtime. You should add '"win": {}' inside your "runtimes" section in your project.json, and then re-run NuGet restore.

我已经添加了 "win",这开始感觉像是在转移注意力。我在做什么直接改变 project.json,不是 NuGet 处理这个吗?

其实我刚刚想通了这个问题。我最终在解决方案级别单击 Restore Nuget Packages,并设法编译了我的 PCL 文件,然后是我的解决方案的其余部分。

希望对您有所帮助。

我发现一个流氓 project.lock.json 给我造成了这个问题。删除文件后,问题就消失了。

Here 是关于 project.lock.json 的一些文档。

一些进一步的建议是确保 project.lock.json 在您的 git 忽略文件中被忽略,并尝试完全 git 清理。不过,在执行此操作之前,请确保您了解 Git 清理的含义。

我遇到了同样的问题,最后我不仅要删除 binobj 文件夹的内容,还要删除 .vs 目录的解决方案。

我遇到了同样的问题 - 使用 Visual Studio 2017.3 时仍然会出现这种情况,它使用 .csproj 文件而不是 project.json。有趣的是,错误消息仍然包含文本 "project.json".

看来此问题的原因是来自先前构建的锁定文件或 obj\project.assets.json 文件(取决于您的 VS 版本),在清理期间未删除,as described here

手动删除 /obj 目录是一种快速解决方法。

如果您在同一目录中有一个 "new" 项目(例如在 VS 2017 中创建的 .NET Core 或 netstandard 项目)和一个 "old" 项目(例如在 VS 2015 中创建的 .NET 4.6 项目) ), 看起来他们会继续战斗,因为他们都以不同的方式使用 ./obj 目录。 More info here..

msbuild 解决方法是让您的项目之一使用不同的 obj 目录。我将此添加到我的 "old" csproj:

<PropertyGroup>
  <!-- Needed due to old project and new project in same directory: https://github.com/NuGet/Home/issues/5126 -->
  <BaseIntermediateOutputPath>obj_netfx\</BaseIntermediateOutputPath>
</PropertyGroup>

为 Mac 7.4(内部版本 1033)更新到 Visual Studio 后,我遇到了同样的问题:

Error: Your project is not referencing the "MonoAndroid,Version=v7.1" framework. Add a reference to "MonoAndroid,Version=v7.1" in the "frameworks" section of your project.json, and then re-run NuGet restore.

我没有任何 json 项目文件。这里的提示也没有帮助,所以我不得不找出除了我的目标 SDK (Nougat 7.1) 之外还必须安装最新的 Android SDK (Oreo 8.1) 的困难方法。

我有同样的问题,但我已经通过在 vs2017-->tools-->options-->Nugetpacakge manager--->updated 正确的包 url.

参考下图