I found what was causing the problem for me. In the project, there was an existing set of `Web.*.config files - Web.config, Web.Debug.config,Web.InternalProd.config.... Those files were probably leftover from a .Net Framework to .Net Core 2.2 migration (I inherited that project).
After deleting all of those Web.*.config
files and then running the dotnet publish
command it resulted in properly generated web.config
(new one) file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
...
</configuration>