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:
- The project file (e.g.,
csproj
) - 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 thecsproj
file, but that is not the case.
Text Editor
To make this modification via a text editor,
- Open the
~/Properties/PublishProfiles
folder. - Open the
*.pubxml
you wish to edit. - Modify the value of
<TargetFramework>
tonetcoreapp3.1
:
<TargetFramework>netcoreapp3.1</TargetFramework>
Visual Studio 2019
To make this modification via the Visual Studio 2019 IDE,
- Click the gear icon ⚙ on the Web One Click Publish toolbar (it's to the right of the publish icon).
- Assuming the Target Framework is not set to
netcoreapp3.1
, click the edit icon next to it. - Ensure that the Target Framework is set to
netcoreapp3.1
. - 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).