Visual Studio – Your project does not reference .NETFramework – How to fix How to fix the 'Your project does not reference ".NETFramework,Version=v4.7.2" framework' Visual Studio build error when upgrading the .NET Framework version of an existing Visual Studio ASP.NET project

Visual Studio 2017 - Lost Razor Intellisense and Syntax Highlight - How to Fix it

If you’ve stumbled upon this post, it most likely means that you’ve switched the .NET Runtime Framework of your ASP.NET project(s) to a newer 4.x version, such as .NET Framework 4.7.2…

Visual Studio - Your project does not reference .NETFramework - How to fix

… And, right after changing that setting, getting the following error:

Your project does not reference “.NETFramework,Version=v4.7.2” framework. Add a reference to “.NETFramework,Version=v4.7.2” in the “TargetFrameworks” property of your project file and then re-run NuGet restore.

I had to deal with such issue today and I was kind of lost, since the error message gives no indication at all regarding the configuration file containing that wrong reference.

StackOverflow to the rescue

Eventually I had the luck to find this StackOverflow thread that told me what to do. The issue was due to the presence of an odd project.assets.json file in the /obj/ folder, which pointed to the previous framework version (in my case 4.6.2) instead of the one I’ve selected for the update (4.7.2):

Visual Studio - Your project does not reference .NETFramework - How to fix

It seems like this project.assets.json file file is a leftover of some previous .NET Framework versions, most likely < than 4.7.2: oddly enough, such file is not removed or updated when the .NET Framework version of the project change or by the Build, Rebuild or Clean commands.

Anyway, once the root of the issue became clear, the fix was very simple: manually deleting the /obj/ folder of each affected project made the error disappear and allowed Visual Studio to build the project successfully. While I was there, I also took the chance to delete the /bin/ folder as well. Luckily enough these two folders are automatically re-created upon the first successful build, hence they can be both safely deleted to fix these kind of issues.

Conclusion

That’s it, at least for the time being: I hope that this small guide will help other ASP.NET developers who’ll stumble upon this issue in the future. See you next time and… happy building!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.