question

GeorgiKoemdzhiev-4063 avatar image
0 Votes"
GeorgiKoemdzhiev-4063 asked GeorgiKoemdzhiev-4063 commented

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

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?

windows-server-iisdotnet-aspnet-core-general
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@GeorgiKoemdzhiev-4063 As far as I know, dotnet publish command cannot set processPath and arguments, this error means the path %LAUNCHER_PATH% does not exist on your system, it is not even valid.

1 Vote 1 ·

Thank you Sam. What is responsible for the creation of these paths (LAUNCHER_PATH & LAUNCHER_ARGS)? To my knowledge, the dotnet runtime should be set them before launching the app?

0 Votes 0 ·

Sam, please see my answer below. I found the issue of my problem. I saw that there were some (I suspect) leftover web.*.config files from a previous migration (e.g. .Net FR to .Net Core). After I deleted those and republish the app, I got a new web.config with properly filled placeholder values.

To my knowledge, web.config files are not needed with .Net Core projects - app settings files should be used instead

0 Votes 0 ·
Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered GeorgiKoemdzhiev-4063 commented

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

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

|Thank you Bruce. I will try to deploy a 3.1 app and see if I will observe the same behaviour

0 Votes 0 ·


Bruce, please see my answer below. I found the issue of my problem. I saw that there were some (I suspect) leftover web.*.config files from a previous migration (e.g. .Net FR to .Net Core). After I deleted those and republish the app, I got a new web.config with properly filled placeholder values.

To my knowledge, web.config files are not needed with .Net Core projects - app settings files should be used instead

0 Votes 0 ·
Bruce-SqlWork avatar image Bruce-SqlWork GeorgiKoemdzhiev-4063 ·

The web.config file is only used when iis hosts asp.net core. It’s used to configure the aspnetcore hosting module. This web.config can configure environment variables the hosting module can set. The publish can set these variable values in the web.config.

Again this only when hosted in iis.

1 Vote 1 ·
Show more comments
GeorgiKoemdzhiev-4063 avatar image
0 Votes"
GeorgiKoemdzhiev-4063 answered SamWu-MSFT commented

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>


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm so glad that the problem has been resolved. It is so appreciated if you can accept your solution as answer.

1 Vote 1 ·