16

I have a solution which contains multiple projects. All projects target v4.6.1 of the .NETFramework. However when I build my solution and try to run it I get the following exception:

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

Can anyone point me in the correct direction? I don't see what is going wrong.

Config1:

<RootNamespace>Exact_Online_Database</RootNamespace>
<AssemblyName>Exact_Online_Database</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

Config2:

<RootNamespace>ExactOnlineConsoleApp</RootNamespace>
<AssemblyName>ExactOnlineConsoleApp</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

Config3:

<RootNamespace>Exact_Online_Services</RootNamespace>
<AssemblyName>Exact Online Services</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

Config4:

<RootNamespace>Example</RootNamespace>
<AssemblyName>Example</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
Bart Schelkens
  • 1,235
  • 4
  • 21
  • 45
  • Did you upgrade from on older version? seems like some file points to an old framework version and thus produces the error. – Aaron May 17 '19 at 10:28
  • @Aaron I didn't upgrade, I checked my files and as far as I can see, they are all correct – Bart Schelkens May 17 '19 at 10:32
  • Hm seems strange to me. Could you try to switch the framework version maybe to 4.7.2 or any other version and then try building the project? For me it just works when I switch the version in properties. – Aaron May 17 '19 at 10:39
  • would you paste your *.csproj files? – Ashkan Rahmani May 17 '19 at 10:42

2 Answers2

44

Deleting the obj folder resolved this issue for me as recommended in Henry He's answer to this question.

For info I came across this issue when I tried to build a project that had been changed to .NET Core (from Framework) on a different branch. When I switched back to a branch with the original framework project it would no longer build.

Rob Willis
  • 4,706
  • 2
  • 28
  • 20
  • I did the exact same thing. I wonder why switching back to previous git branch did not fix the issue... Once again stack overflow saves me who knows how much time. – Jeremy A. West Sep 23 '22 at 13:14
1

Did you recently change from an older version of Visual Studio to VS 2017 to build your solution? It appears that the build process is looking for the <TargetFrameworks> element, not the <TargetFrameworkVersion>.

Refer to the documentation here for more info.

jtate
  • 2,612
  • 7
  • 25
  • 35