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

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I am using 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.

I am getting this error on my Data Access and Business Logic layers, shortly after adding to my MVC Layer. Things were building fine until then, but I don't know what triggered this error. Here is my 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"       }     }   } }

Here's what I have tried:

  1. Replacing "dotnet5.4" with "net451" (and deleting it) as found in this answer.

Result is the same error.

  1. Replacing "dotnet5.4" with "net45" and leaving the "net451". This results in a new error:

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

I tried doing as this error suggested and adding

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

This got me this error, which I can't seem to move past:

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.

I've already added "win", and this is beginning to feel like a red herring. What am I doing altering the project.json directly, isn't NuGet handling this?

回答1:

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.



回答2:

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.



回答3:

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:

obj_netfx\


回答4:

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



回答5:

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).



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!