How to instruct dotnet publish command to fill in my web.config values?

Georgi Koemdzhiev 61 Reputation points
2021-11-04T09:14:06.997+00:00

I publish a .Net Core 2.2 project using this command dotnet.exe publish -o "C:\temp\api" /property:Configuration=Debug

However, if I inspect the web.config file it still has placeholders such as %LAUNCHER_PATH% and %LAUNCHER_ARGS%:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
        <environmentVariables>
          <clear />
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

When I deploy the app to IIS server (with the above web.config) I see this error in the EventViewer:

Application 'C:\inetpub\api\' failed to start. Exception message:
Executable was not found at 'C:\inetpub\api\%LAUNCHER_PATH%.exe'

Is there a way to instruct the dotnet publish command that I want LAUNCHER_PATH & LAUNCHER_ARGS placeholder variables to be replaced by dotnet and the ProjetName.dll respectively?

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,148 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,196 Reputation points
    2021-11-04T17:57:24.823+00:00

    core 2.2 is not longer supported (ended: 12/23/2019), but supported versions work as expected.


  2. Georgi Koemdzhiev 61 Reputation points
    2021-11-05T09:35:39.713+00:00

    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>