15

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.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Velocedge
  • 1,222
  • 1
  • 11
  • 35

6 Answers6

20

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.

Velocedge
  • 1,222
  • 1
  • 11
  • 35
  • Are you using v5.0.11 of the Hosting Bundle? Does that run the net6.0 application? – Steven Frank Nov 08 '21 at 15:48
  • 1
    For my project, I had no Target Framework specified in the publish profile at all, which never made any difference in the past. (The TFM is in the csproj file; why would it need to be in the publish profile as well?) Adding the TFM fixed the issue. – Doug Nov 10 '21 at 21:40
  • Same as Doug for me - I had to add the TFM net6.0 to the publish profile (pubxml) – Will Feb 18 '22 at 13:05
  • Where in Visual Studio did you edit the publishing information? – Chris Halcrow Jun 30 '22 at 11:16
6

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
Mehmet Topçu
  • 1
  • 1
  • 16
  • 31
2

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.

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
1

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

Ajay Kopperla
  • 199
  • 2
  • 5
1

In my case I was migrating from .Net 6 to .Net 7 tried many solutions offered in other posts but it was Vivek Nuna's comment above that was the key for me to "check the .pubxml file". When I updated it to the correct Target Framework it fixed the issue:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <DeleteExistingFiles>false</DeleteExistingFiles>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>\\someserver\wwwroot\someapp\</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <TargetFramework>net7.0</TargetFramework>
    <ProjectGuid>a1e50b13-5370-4e52-86f3-9386c075311e</ProjectGuid>
    <SelfContained>false</SelfContained>
  </PropertyGroup>
</Project>
Anthony Griggs
  • 1,469
  • 2
  • 17
  • 39
0

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

simi
  • 173
  • 2
  • 7