Error publishing an ASP.NET Core 3.1 site to Azure from Visual Studio 2019
Asked Answered
S

4

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

  • My csproj file's <TargetFramework> is correctly set to netcoreapp3.1.
  • 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. Is Azure App Service not yet ready for .NET Core 3.1? Or is this an issue with the dependency resolution targets?

Sclerenchyma answered 4/12, 2019 at 8:17 Comment(4)
The docs show how to explicitly select the .NET Core SDK version. Have you tried that? Does the 3.1 SDK appear in the list?Af
@PanagiotisKanavos: This project isn't published using Azure Pipelines yet. That said, this does remind me that there's also a <TargetFramework> 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!Sclerenchyma
Aah, timezone differences ...Af
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.Depression
S
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.

Acknowledgements

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

Sclerenchyma answered 4/12, 2019 at 21:6 Comment(4)
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!Young
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...Young
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.)Sclerenchyma
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. ThanksIcosahedron
L
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

Letter answered 11/12, 2019 at 14:14 Comment(1)
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!Sclerenchyma
V
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

Viv answered 18/1, 2021 at 19:37 Comment(0)
W
0

change

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

works for me.

Westney answered 9/12, 2019 at 8:20 Comment(4)
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.Sclerenchyma
The version of two above mentioned packages are currently in 2.2.0 and marked as latest version.Westney
@Libertad, you need to upgrade your visual studio installation to version 16.4.0 to see latest dot net core 3.1 versionProvide
@Provide my VS is uptodate. Aabove packages are just nuget package. Take a look at this: nuget.org/packages/Microsoft.AspNetCore and see its latest versionWestney

© 2022 - 2024 — McMap. All rights reserved.