11
votes

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>
2
Did you upgrade from on older version? seems like some file points to an old framework version and thus produces the error.Aaron
@Aaron I didn't upgrade, I checked my files and as far as I can see, they are all correctBart Schelkens
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
would you paste your *.csproj files?Ashkan Rahmani

2 Answers

31
votes

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.

0
votes

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.