Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgraded Target Framework from 4.7 to 4.7.1 Nu-Get cannot restore packages

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

like image 720
Joe Avatar asked Mar 27 '19 15:03

Joe


1 Answers

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).

like image 112
Joe Avatar answered Jan 04 '23 09:01

Joe