8

I just changed the target framework of all 11 projects in my Visual Studio 2017 solution from .NET 4.7 to .NET 4.7.1. But now, every single time I try to build, I get the following error from NuGet

1>------ Build started: Project: GS.Core, Configuration: Debug x64 ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5): error : Your project does not reference ".NETFramework,Version=v4.7.1" framework. Add a reference to ".NETFramework,Version=v4.7.1" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
StopOnFirstBuildError: Build cancelled because project "GS.Core" failed to build.
Build has been canceled.

If I look in the .csproj file, I do see that the target framework has changed.

<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

And I don't see a "TargetFrameworks" section, just "TargetFrameworkVersion"

Just for laughs I tried actually adding a key with that name, exactly as the error message specified.

<TargetFrameworks>.NETFramework,Version=v4.7.1</TargetFrameworks>

That was a bad idea. Visual Studio exploded when I tried to load it.

My default package management format is "PackageReference", if that matters.

I tried the fix listed in this question, but that had no effect.

Is there a way to fix this? I'm happy to manually edit project files if necessary. I would very much like to go to 4.7.1

Joe
  • 5,394
  • 3
  • 23
  • 54
  • 1
    That looks like a .NETCore build error message. Well, good match for a project named "GS.Core", you probably shouldn't try to target .NETFramework. .NETCore does it differently: https://learn.microsoft.com/en-us/dotnet/standard/frameworks – Hans Passant Mar 27 '19 at 15:49
  • Hi Hans. Actually all of my projects target the standard .NET Framework. I realize the name is "Core" but that's just a coincidence. I've been using this project with .NET 4.7 for over a year now – Joe Mar 27 '19 at 15:55

1 Answers1

21

Answering my own question because after a great deal of googling, I stumbled on the answer on on the MS developer community forum

https://developercommunity.visualstudio.com/content/problem/317628/your-project-does-not-reference-netframeworkversio.html

The culprit appears to be a project.assets.json file in the .OBJ folder. The workaround is to delete all the bin and .OBJ folders and rebuild. MS notes that since there is a workaround, this a low-priority problem.

Note that cleaning the solution did not help. I had to manually delete the folders. I guess the json file isn't considered a part of the build, even though it lives there.

(I should say I cannot say definitively that was literally .json file. I deleted the folders once I saw the recommendation and never looked for one. But I'm guessing that's ti).

Joe
  • 5,394
  • 3
  • 23
  • 54
  • 1
    Can't imagine this is the solution. Thanks a ton. – Sriram Sakthivel Jun 18 '19 at 18:35
  • 1
    I have made a PowerShell script for the same which will delete bin and obj folder from every project: Just Run this at solution level folder. 1. Get-ChildItem bin -Recurse | ForEach-Object { Remove-Item -Path $_.FullName } 2. Get-ChildItem obj -Recurse | ForEach-Object { Remove-Item -Path $_.FullName } – OhmnioX Jun 26 '19 at 05:32
  • 1
    Its important to delete more than the Startup project bin/obj folders. I did that first, and it didnt help. I had to go into the referenced project and delete the folders there, not in the outout folder for the startup project. – Ted Oct 14 '19 at 13:16