Repository navigation
Description
Matching Developer Community report: https://developercommunity.visualstudio.com/content/problem/317628/your-project-does-not-reference-netframeworkversio.html
Since I noticed this recently myself, I thought I would add an issue here to provide some detailed repro steps for the behavior in case they might be useful.
Details about Problem
NuGet product used: NuGet Package Manager in Visual Studio
NuGet version: 4.6.0
Visual Studio versions: Visual 2017 versions 15.8.6 and 15.9 Preview 3.
OS version: Windows 10 Version 1803 (OS Build 17134.285)
Detailed repro steps
- Open Visual Studio and ensure that Tools > NuGet Package Manager > Package Manager Settings > Default package management format is set to PackageReference. (The issue does not affect Packages.config package management.)
- Create a new Visual C# > Console App (.NET Framework) project.
- Open the NuGet Package Manager for project.
- Install a NuGet package (for example, the NuGet.Versioning package).
- Uninstall the NuGet package.
- Open the project properties, change the Target framework to a different value, and select Yes when prompted by the alert window.
- Attempt to build the project.
(You can skip to step 5 if you open the attached sample project instead.)
Other suggested things
Cleaning the project is not sufficient to resolve the issue, but manually deleting the generated obj\project.assets.json file is.
If you manually delete the obj\project.assets.json file for a project that still has a PackageReference, then NuGet.exe restore on the command line will regenerate the file, similar to the behavior within Visual Studio.
Verbose Logs
InstallPackage.txt
UninstallPackage.txt
Diagnostic MSBuild output for the build error:
1>Target "ResolveNuGetPackageAssets: (TargetId:16)" in file "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets" from project "C:\tmp\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj" (target "ResolveAssemblyReferences" depends on it):
1>Using "ResolveNuGetPackageAssets" task from assembly "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.Build.Tasks.dll".
1>Task "ResolveNuGetPackageAssets" (TaskId:9)
1> Task Parameter:IncludeFrameworkReferences=True (TaskId:9)
1> Task Parameter:RuntimeIdentifier=win (TaskId:9)
1> Task Parameter:ProjectLanguage=C# (TaskId:9)
1> Task Parameter:ProjectLockFile=C:\tmp\ConsoleApp1\ConsoleApp1\obj\project.assets.json (TaskId:9)
1> Task Parameter:
1> ContentPreprocessorValues=
1> rootnamespace
1> Value=ConsoleApp1
1> assemblyname
1> Value=ConsoleApp1
1> fullpath
1> Value=C:\tmp\ConsoleApp1\ConsoleApp1
1> outputfilename
1> Value=ConsoleApp1.exe
1> filename
1> Value=ConsoleApp1.csproj (TaskId:9)
1> Task Parameter:ContentPreprocessorOutputDirectory=obj\Debug\\NuGet (TaskId:9)
1> Task Parameter:TargetMonikers=.NETFramework,Version=v4.6.2 (TaskId:9)
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5): error : Your project does not reference ".NETFramework,Version=v4.6.2" framework. Add a reference to ".NETFramework,Version=v4.6.2" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
1>Done executing task "ResolveNuGetPackageAssets" -- FAILED. (TaskId:9)
1>Done building target "ResolveNuGetPackageAssets" in project "ConsoleApp1.csproj" -- FAILED.: (TargetId:16)
Activity
[-]Stale projects.assets.json file after uninstalling all NuGet packages results in a build error "Your project does not reference ..."[/-][+]Stale projects.assets.json file after uninstalling all NuGet packages and changing project Target framework results in a build error "Your project does not reference ..."[/+][-]Stale projects.assets.json file after uninstalling all NuGet packages and changing project Target framework results in a build error "Your project does not reference ..."[/-][+]Stale projects.assets.json file after uninstalling all NuGet packages and changing Target framework results in a build error "Your project does not reference ..."[/+]rrelyea commentedon Oct 11, 2018
Please let us know if this is a new problem. Right now, I'm putting in 5.0 since I believe it is not a regression.
brendanzagaeski commentedon Oct 19, 2018
That sounds correct to me. I got a chance to double-check the behavior today on Visual Studio 2017 version 15.1 with NuGet Package Manager version 4.1.0, and it was the same there too, so I think the PackageReference style of package management has always behaved this way.
vchekan commentedon Dec 18, 2018
Why Rebuild/Clean does not clean all "obj" folder? Issues like this one impact developers productivity.
nkolev92 commentedon Jan 25, 2019
This is a duplicate of dotnet/project-system#3164.
@vchekan
If the assets file was deleted during clean, it would kill intellisense and lead to an ugly experience.