Skip to content

Stale projects.assets.json file after uninstalling all NuGet packages and changing Target framework results in a build error "Your project does not reference ..." #7368

Closed

Description

@brendanzagaeski

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

  1. 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.)
  2. Create a new Visual C# > Console App (.NET Framework) project.
  3. Open the NuGet Package Manager for project.
  4. Install a NuGet package (for example, the NuGet.Versioning package).
  5. Uninstall the NuGet package.
  6. Open the project properties, change the Target framework to a different value, and select Yes when prompted by the alert window.
  7. 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)

Sample Project

ConsoleApp1.zip

Activity

  1. changed the title [-]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 ..."[/+] on Oct 5, 2018
  2. changed the title [-]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 ..."[/+] on Oct 5, 2018
  3. added this to the 5.0 milestone on Oct 11, 2018
  4. rrelyea commented on Oct 11, 2018

    @rrelyea
    Contributor

    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.

  5. brendanzagaeski commented on Oct 19, 2018

    @brendanzagaeski
    Author

    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.

  6. vchekan commented on Dec 18, 2018

    @vchekan

    Why Rebuild/Clean does not clean all "obj" folder? Issues like this one impact developers productivity.

  7. nkolev92 commented on Jan 25, 2019

    @nkolev92
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions