Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone!

Currently I am running the command below on my CI/CD pipeline, everything is working as expected.

& dotnet publish "$projectSolution" --output $outputDir --configuration $Configuration /p:EnvironmentName=$Environment --verbosity quiet


This will generate the following web.config file

XML
<?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="dotnet" arguments=".\{projectSolution}.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>


However, I wanted to add a command line argument to the arguments in the web.config file in the aspNetCore node. So if I add the argument manually

XML
<aspNetCore processPath="dotnet" arguments=".\{projectSolution}.dll new_argument" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
  </environmentVariables>
</aspNetCore>


The code will work, but I don't know how to add the argument new_argument using the dotnet publish command so that the file is automatically generated with the argument added. Any help is greatly appreciated.

What I have tried:

I have looked over many times about adding arguments from the documentation dotnet run command - .NET CLI | Microsoft Docs[^] but to no avail.
Posted
Updated 29-Nov-21 22:14pm

1 solution

Use a web config transformation file:
Transform web.config | Microsoft Docs[^]
 
Share this answer
 
Comments
instantmaker 30-Nov-21 23:39pm    
Hi, Richard, thanks for the help. I looked over the examples and everything I see is on the node level instead of inserting to the attribute level. Do you mind sharing some sample code that I can look at please?
Richard Deeming 1-Dec-21 3:24am    
Something like this should work:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <aspNetCore 
        processPath="dotnet"
        arguments=".\{projectSolution}.dll" 
        xdt:Transform="SetAttributes" 
        xdt:Locator="Match(processPath)"
      />
    </system.webServer>
  </location>
</configuration>
instantmaker 1-Dec-21 9:03am    
hi, this works great except that now the arguments really becomes .\{projectSolution}.dll new_argument. So I just create one that will have the solution named hard coded for now. don't know if this is the right way to do this, thanks so much for the help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900