Migrating to .NET 6.0 error on publish: Assets file doesn't have a target for 'net5.0'

Viewed 10198

I'm trying to migrate from .NET 5 to .NET 6. I've installed VS 2022 Community Preview and the Hosting Bundle... and updated everything in NuGet. The project will build without errors but when I go to publish it, I get the following error:

Assets file 'D:\Data\CADE.core\FileManager\FileManager\obj\project.assets.json' doesn't have a target for 'net5.0'. 
Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project.

I don't know why it's still looking for .NET 5 nor how to fix this error.

5 Answers

With everyone's help, I found the solution. I edited the publishing information and there was a red dot by Target Framework net6.0. I clicked the drop-down and one of the options was "net6.0-windows". I selected that and it published correctly.

Although the error seems not to be related to nuget, it is actually related to nuget.

Open a PowerShell window and enter the following command:

dotnet new nugetconfig

In My case. i had opened the solution in VS 2019 and VS 2022. when it tries to restore i think it is restoring with 2019 and building on 2022. closing the VS 2019 and deleting the obj and bin and rebuilding solved the issue

I had install from tools->nuget package manager->search for target and install targets. Then cntrol plus f5 and everythings when fine.

Check restore is working using dotnet restore from the command line. It can make any issues with the restore more obvious.

This type of error can occur if a Nuget package source specified in Visual Studio is inaccessible for some reason. You can view configured nuget package sources under Tools > Options > Nuget Package Manager > Package Sources.

Related