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

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


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