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

我正在使用 VS 2015。

您的项目没有引用“ . NETFramework,Version = 4.5” 框架中添加对“ . NETFramework,Version = 4.5”的引用 Json 文件中的“ Framework”部分,然后重新运行 NuGet 恢复。

在添加到 MVC 层后不久,我在数据访问和业务逻辑层上出现了这个错误。在那之前,一切都很好,但我不知道是什么触发了这个错误。这是我的项目。 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”(并删除它) ,如 这个答案所示。

结果是同样的错误。

  1. 用“ net45”替换“ dotnet5.4”并保留“ net451”。这会导致一个新的错误:

Json 没有运行时部分,您应该添加 “ runtimes”: {“ win”: {}}”到 project.json,然后重新运行 NuGet 恢复。

我尝试按照这个错误的建议和添加操作

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

这给我带来了一个错误,我似乎无法克服它:

Json 没有将“ win”列为目标运行时 在 project.json 的“ runtimes”部分中添加“ win”: {}”, 然后重新运行 NuGet 恢复。

我已经加上了“胜利”,这开始让人感觉像是在转移注意力。我为什么要直接改变项目.json 难道不是 NuGet 在处理吗?

44736 次浏览

I actually just figured out the problem. I ended up clicking on Restore Nuget Packages at the solution level and I managed to compile my PCL file, and then the rest of my solution.

Hope this helps.

I found that a rogue project.lock.json was causing this issue for me. Once I deleted the file, the problem went away.

Here is some documentation on project.lock.json.

Some further advice would be to ensure that project.lock.json is ignored in your git ignore file, and to try a full git clean. Make sure you understand the implications of a Git clean before you do that though.

I had this same problem, and I ended up having to not only delete the contents of bin and obj folders, but also the .vs directory for the solution.

I had the same problem - this occurs still using Visual Studio 2017.3, which uses .csproj files instead of project.json. Interestingly, the error message still contains the text "project.json".

It appears the cause of this issue is a lock file or obj\project.assets.json file (depending on your version of VS) from a previous build, which is not removed during a clean, as described here.

Manually deleting the /obj directory is a quick workaround.

If you have a "new" project (eg .NET Core or netstandard project created in VS 2017) and an "old" project in the same directory (eg .NET 4.6 project created in VS 2015), it appears they will continually fight because they both use the ./obj dir in different ways. More info here..

The msbuild workaround is to make one of your projects use a different obj dir. I added this to my "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>

I had the same issue after updating to Visual Studio for Mac 7.4 (build 1033):

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.

I don't have any json project files. The tips in here did not help either, so I had to find out the hard way that I had to install the lastest Android SDK (Oreo 8.1) in addition to my target SDK (Nougat 7.1).

enter image description here

I have same issue, but i've solved by adding proper nugget package resource at vs2017-->tools-->options-->Nugetpacakge manager--->updated the proper package url.

Refer below image

enter image description here