Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 633
Jeremy Caney Avatar asked Dec 04 '19 08:12

Jeremy Caney


2 Answers

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

like image 94
BobbyTables Avatar answered Oct 31 '22 02:10

BobbyTables


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).

like image 36
Jeremy Caney Avatar answered Oct 31 '22 03:10

Jeremy Caney