How to fix `Your project does not reference ".NETFramework,Version=v4.6.1" framework...`
I found this link from a google search and tried it and it fixed my issue so I thought I might share that deleting the obj folders seems to work.
As it states in forum:
I had the same with an old project (after using git to move to an old version locally). Deleting the 'obj' folders fixed the issue, clean is insufficient.
Two users found that this fix the issue. Most also found doing a clean and then removing the obj folder by hand then redoing a nuget restore seemed to fix the issue.
Build error while transitioning between branches: Your project is not referencing the ".NETFramework,Version=v4.7.2" framework
Fix this by automatically deleting project.assets.json
for non-Core project(s) via a custom Visual Studio Build Event.
Update (6/13/2020)
It turned out deleting project.assets.json
caused squiggy lines to show because Intellisense needed the references from the file. So an even better fix is to use a Pre-build event to only delete the file if the project is not .Net Core.
This is identified by $(TargetFramework) ---> "netcoreapp3.1"
on my computer. Your installed framework might show a different identifier so update the script accordingly (see the text in your build Output window generated by the ECHO
on line 2). Note: This can be an empty string on certain .Net Framework version(s) which shouldn't be an issue. We're also only comparing the first 7 characters to ignore the version to avoid having to update the script if/when the version changes.
SET _tgt=$(TargetFramework)
ECHO %_tgt%
IF NOT "%_tgt:~0,7%" == "netcore" (
cd $(ProjectDir)\obj
DEL project.assets.json
)
==== Update (6/13/2020) ends here. Original answer kept below to provide context. ====
We narrowed down the problem to a single file: project.assets.json
in the {Your project}/obj
folder. It's a file created by a .Net Core project but it does not get deleted by Visual Studio after switching to a .Net Framework project causing the issue mentioned by OP.
The solution is to remove this file but, rather than having to delete it manually every time we need to switch projects, we created a post-build event in Visual Studio to remove it after each successful Core build (your Core projects won't build if you run the script before the build, obviously). You can customize the script to delete whatever files/folders you deem to be problematic but our issue was limited to that single file.
cd $(ProjectDir)\obj
del project.assets.json
Note: You will need to delete the offending artifact(s) manually once if it already exists since the post-build event will only run after a successful build.
how do I share a class between ASP .NET and Framework 4.6 applications?
You can share a library if you build it for .NET Standard. To share a .NET Standard 2.0 library you'll need to target at least .NET Framework 4.6.1, which will be fine unless you need to deploy to Windows Vista or Windows Server 2008, which are both long out-of-support.
Related Topics
Declare Properties to Ignore in Entities Interface (Ef Core)
C# - Comparing Items Between 2 Lists
How Does Httpcontext.Current.User.Identity.Name Know Which Usernames Exist
Automatically Update Values in Database from Datagridview
Error 5:Access Denied When Starting Windows Service
How to Determine If a Json Object Contains Only a Specific Key
Formatting Date in Linq-To-Entities Query Causes Exception
How to Delete a Read-Only File
Create Global Variable in .Net Core 2.0 to Use in Razor Views
Fast Way of Finding Most and Least Significant Bit Set in a 64-Bit Integer
How to Secure the Asp.Net_Sessionid Cookie
How to Set Datetimepicker to Month and Year Only Format
How to Handle [Null] Values of Datetime from SQL Server to a Datetimepicker
Replace Single Backslash With Double Backslash
Asp.Net Core Localization Decimal Field Dot and Comma
Using Selenium2, How to Check If Certain Text Exists on the Page