Aspnetcore: Net Core 3.0 Project Suddenly Failing to Publish But Will Still Build and Preview - project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2

Created on 9 Oct 2019  路  14Comments  路  Source: dotnet/aspnetcore

I successfully migrated and then built and published a .NET Core 3.0 app and then wanted to make a minor adjustment to the appsettings.json file but then minutes later it refuses to publish again with the error:

Assets file '...\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2'. Ensure that restore has run and that you have included 'netcoreapp2.2' in the TargetFrameworks for your project.

When I previously hit this error with a different project I was migrating I was able to delete the bin and obj folders and then run dotnet build and this fixed the issue. However in this case it makes no difference and I have tried rebuilding/cleaning etc. but it still refuses to publish.

It is correctly targeting .NET Core 3.0 so I have no idea why it suddenly thinks it needs 2.2 again.

To avoid having to revert my project a second time (first time it was suddenly complaining about C# 4 for some reason and underlining most of the code in the cshtml files) is there anything I can do to salvage this?

Thanks
Robin

External

Most helpful comment

@robinwilson16 I ended up having to delete/recreate the publish profile and then was able to successfully publish.

Encountered the same issue after upgrading the project to .NET Core 3.0 and then installing the latest (3.0) hosting bundle on the server. Opening the options and clicking save did not work for me. I tried to change other settings to see if the value would update, but no luck.

Visual Studio Version: 16.3.5

All 14 comments

Ok I have solved it but not sure why it is like this. According to the publishing profile the target framework is netcoreapp3.0:

image

However the pubxml file says it is targeting netcoreapp2.2 at ProjectPropertiesPublishProfilesFolderProfile.pubxml:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>757ec417-a480-490e-91d8-8f8c2e542547</ProjectGuid>
    <publishUrl>C:\Users\robin\source\repos\PremierKitchensDB</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <SelfContained>false</SelfContained>
    <_IsPortable>true</_IsPortable>
  </PropertyGroup>
</Project>

Seems strange this would suddenly switch itself plus not match what is shown on screen.
Anyway at least it is working and I will know what to do if it happens again.

Robin

@robinwilson16 Thanks for contacting us.

@vijayrkn I think this is a VS publish issue, can you take a look or get someone else to look at it?

Ping @vijayrkn ?

The TFM persisted in the profile. So after the project migration, the settings dialog needs to be opened in order to switch the profile to target 3.0

If you see the settings dialog that you have shared above, it has unsaved changes. when you open the dialog, we detect that 3.0 is the only valid option. So a save is needed to update the TFM in profile.

I don't see any other issues listed above.

Closing as answered, @robinwilson16 let us know if you're still seeing anything.

@Pilchie I can confirm that pressing Save does absolutely nothing at all (at least in my copy) and I have now updated 11 projects to .NET Core 3.0 (I didn't try save in all 11 though as had worked out how to manually update by this point).

It shows as 3.0 on the GUI but is 2.2 in FolderProfile.pubxml and with that setting in place as 2.2 it seems sometimes it publishes correctly as 3.0 and other times it fails due to trying to publish the 3.0 project as 2.2 and manually updating that file has been required to fix this. The fact it worked initially made it all the more confusing. Obviously I thought some of my code commits had done something so started troubleshooting changes I had made and reverting until I realised it was an issue with VS itself (e.g. undid all my changes and still received the error having successfully published just 30mins prior).

I have not tried again since the more recent updates to VS but all my projects are up to date now so I won't need to do this again unless I inherit any older projects.

I added a guide here on how to update to 3.0 as the official guide does not cover a lot of things such as the above: aspnet/AspNetCore.Docs#14817

@robinwilson16 I ended up having to delete/recreate the publish profile and then was able to successfully publish.

Encountered the same issue after upgrading the project to .NET Core 3.0 and then installing the latest (3.0) hosting bundle on the server. Opening the options and clicking save did not work for me. I tried to change other settings to see if the value would update, but no luck.

Visual Studio Version: 16.3.5

It's a shame these issues just gets closed straight away and no-one tests or fixes the problem

@robinwilson16 Sorry about that. We get a lot of issues and sometimes we loose track of things a bit. I'm reopening based on the new information you provided.

@vijayrkn do you have any thoughts?

@robinwilson16 It will also help if you file the issue through the send VS feedback dialog.

@robinwilson16 @NuNn-DaDdY -

I just tried opening the edit page & clicking save after migrating the project to 3.0 & I am unable to reproduce this issue with 16.3.9

image

Would it be possible to provide a sample project with profile where this scenario doesnt work? This will help us get to the root of the issue. Appreciate your help with this.

Hello @javiercn
Unfortunately I have now migrated all my projects to 3.0. Maybe this issue was fixed in a more recent update as I hit the issue a month ago and it happened with all my projects which had all been created at different points but all had the issue.
If it happens again I will let you know but for now all the projects I am working on are already at version 3.0 so I don't have anything to test with.

I'm experiencing precisely the same issue described above after migrating a project to 3.1. VS v16.4.1.

I've just have had a similar issue. In my case I had to manually update in

Properties > PublishProfiles > FolderProfile.pubxml

to the correct version. Now I can publish my project.

This still isn't fixed and also occurs when migrating from .NET 3.0 to 3.1.
I have linked the new issue to this one.
New issue for NET Core 3.1 is logged here: dotnet/core#4064

Was this page helpful?
0 / 5 - 0 ratings