12

I have a preexisting ASP.NET Core 3.0 application which is successfully deployed to an Azure App Service (using the AspNetCoreModuleV2 module). After upgrading the app to (today's release of) ASP.NET Core 3.1, the application builds and runs correctly on my local version of IIS Express. When I attempt to publish to the Azure App Service using (today's release of) Visual Studio 16.4, however, I receive the following error:

Assets file 'C:\Project\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project.

Notes

  • All <PackageReference>'s to Microsoft.AspNetCore, Microsoft.EntityFrameworkCore, and Microsoft.Extensions have been updated to 3.1.0
  • I have cleaned my solution, and even nuked my obj folder to ensure there aren't any lingering references.
  • This error is being generated from the 3.1.100 version of Microsoft.PackageDependencyResolution.targets.

I get that something is still hanging onto the .NET Core 3.0 dependencies. But it's unclear why that's only causing problems during deployment. Are Azure App Service's not yet ready for .NET Core 3.1? Or is this an issue with the dependency resolution targets?

Jeremy Caney
  • 4,585
  • 13
  • 32
  • 54
  • Thank you @Panagiotis Kanavos for tagging this with `asp.net-core-3.1`. I lacked the necessary reputation to create a new tag. – Jeremy Caney Dec 04 '19 at 08:43
  • Obviously, my next step will be to start with a fresh **ASP.NET Core 3.1** project template, attempt to deploy to a fresh **Azure App service**, and then reintroduce dependencies until I'm able to reproduce the problem. I won't have time to do that until later this week. Until then, I was hoping someone else might have some insight into this type of error, or have found a solution themselves. – Jeremy Caney Dec 04 '19 at 08:46
  • The docs [show how to explicitly select the .NET Core SDK version](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/?view=aspnetcore-3.1&tabs=visual-studio#deploy-aspnet-core-30-to-azure-app-service). Have you tried that? Does the 3.1 SDK appear in the list? – Panagiotis Kanavos Dec 04 '19 at 08:47
  • @PanagiotisKanavos: This project isn't published using **Azure Pipelines** yet. That said, this _does_ remind me that there's _also_ a `` setting in the `pubxml` profile that **Visual Studio** relies on, which I spaced on. Oops! Changing that to `netcoreapp3.1` to match the `csproj` target resolves the immediate issue. (This introduces a new issue with **Azure App Service** itself tripping on the target, but that can probably be resolved by using a self-contained deployment, similar to the link you provided.) Thank you for pointing me in the right direction! – Jeremy Caney Dec 04 '19 at 09:20
  • Aah, timezone differences ... – Panagiotis Kanavos Dec 04 '19 at 09:24
  • 1
    Well thank goodness for finding this question (and answer). I am starting to get pretty frustrated with adopting bleeding edge MS changes (on their recommendation and encouragement) only to keep running into issues like this. – Frank Dec 30 '19 at 12:59

4 Answers4

16

The immediate issue—as identified in the original question—has to do with there being two places where <TargetFramework> is set:

  1. The project file (e.g., csproj)
  2. The publishing profile (i.e., pubxml)

The <TargetFramework> must be updated in both locations, and they must match exactly. Otherwise, the publishing won't be able to find its targets in the project.assets.json file, which is built based on the <TargetFramework> in the csjproj file.

Note: You may well expect the pubxml file to defer to the <TargetFramework> set in the csproj file, but that is not the case.

Text Editor

To make this modification via a text editor,

  1. Open the ~/Properties/PublishProfiles folder.
  2. Open the *.pubxml you wish to edit.
  3. Modify the value of <TargetFramework> to netcoreapp3.1:
<TargetFramework>netcoreapp3.1</TargetFramework>

Visual Studio 2019

To make this modification via the Visual Studio 2019 IDE,

  1. Click the gear icon on the Web One Click Publish toolbar (it's to the right of the publish icon).
  2. Assuming the Target Framework is not set to netcoreapp3.1, click the edit icon next to it.
  3. Ensure that the Target Framework is set to netcoreapp3.1.
  4. Click Save.

Warning: When using the IDE, you may run into a problem here. When editing the profile you'll likely see the new value from your project file (i.e., netcoreapp3.1) already selected. When you click Save, however, it will revert back to the original value (e.g., netcoreapp3.0 in my case). This is because you didn't actually change the value in the interface, which Visual Studio mistakes for there not being a change to the underlying values. If you temporarily toggle another value (e.g., Configuration), then Visual Studio will recognize that a change has occurred, and both values will be updated in the *.pubxml file.

Thank you, again, to @PanagiotisKanavos for pointing me in the right direction (see comments on original thread).

Jeremy Caney
  • 4,585
  • 13
  • 32
  • 54
  • 1
    Thanks for posting a solution! I was struggling with this when I tried to publish last night and it just didn't make any sense. In the publish wizard it always had 3.1 selected as the target so I figured it was ok, but once I opened the `pubx` file as you explained it was still on 3.0. Very frustrating. Honestly, I've had nothing but weird, obscure and completely show stopping bugs and issues since VS 16.3 and .NET Core 3.0 were released. Thanks again! – Gup3rSuR4c Dec 11 '19 at 04:22
  • Idk if you're getting this too, but it's quite lovely how when you tell it to publish as framework-dependent, it decides to publish the entire framework along with it. A publish that should be 1 min or so, is now 15+ min... – Gup3rSuR4c Dec 11 '19 at 04:41
  • FYI: Since I originally posted this, **Microsoft** has updated the **Azure App Services** to provide native support for **.NET Core 3.1**. Given that, I've removed the warning regarding the `HTTP Error 500.30 - ANCM In-Process Start Failure` message from my original message. Previously, this necessitated publishing a fully self-contained distribution of your application. (That said, there's usually a 2-3 day lag time between a new version of **.NET Core** dropping, and it being integrated into the **Azure App Service** environment, so this is useful to be aware of in future updates.) – Jeremy Caney Dec 20 '19 at 00:36
  • 1
    Nice, I had only updated the framework version in the project properties and didn't even cross my mind about the .pubxml file. This was causing my publish to hang, after updating the .pubxml to "netcoreapp3.1" it worked fine. Thanks – demoncodemonkey Jan 02 '20 at 16:35
2

Open Project folder;

  • Navigate to folder Properties>>PublishProfiles
  • Open file FolderProfile.pubxml then change version 3.0 to 3.1

    netcoreapp3.1

  • Finally, rebuild your application before publishing

  • Good call on providing explicit instructions for modifying the `pubxml` file manually, and especially given the goofiness of modifying these values via the **Visual Studio 2019** GUI. I've incorporated these details into my original answer so this option is explicitly explained. Thank you! – Jeremy Caney Dec 20 '19 at 00:48
1

I got this error from a fresh new net5.0 project in VS2019 (ASP.NET Core Web Application template) when using the VS web-publisher. The solution is as follows:

  1. Open file: {project}\Properties\PublishProfiles\{project} - Web Deploy.pubxml

  2. Add the following line inside the <PropertyGroup> element:

    <TargetFramework>net5.0</TargetFramework>

The element was missing entirely - great work MS

BobbyTables
  • 3,498
  • 1
  • 22
  • 28
0

change

<PackageReferenceInclude="Microsoft.AspNetCore"Version="2.2.0" />
 to 
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />

works for me.

Majid Shahabfar
  • 693
  • 1
  • 11
  • 19
  • 1
    For **ASP.NET Core 3.1**, all `Microsoft.AspNetCore` libraries should be updated to `3.1.0`, as per Microsoft’s v3.1 release notes. Your approach may be a valid fix for similar problems in **ASP.NET Core 2.2**, assuming that the error wasn’t caused by a mismatch between your `csproj` and `pubx` files, as it was in my case. – Jeremy Caney Dec 09 '19 at 09:30
  • The version of two above mentioned packages are currently in 2.2.0 and marked as latest version. – Majid Shahabfar Dec 09 '19 at 10:39
  • 1
    @Libertad, you need to upgrade your visual studio installation to version 16.4.0 to see latest dot net core 3.1 version – navule Dec 10 '19 at 12:50
  • @navule my VS is uptodate. Aabove packages are just nuget package. Take a look at this: https://www.nuget.org/packages/Microsoft.AspNetCore and see its latest version – Majid Shahabfar Dec 11 '19 at 12:27