I have .NET Core 7 WEB API project. In there, I have 3 settings files. More pecisely:
The behavior I want to achieve is:
When I run: dotnet publish -c QA -o deploy
and host the application on IIS, it is using appsettings.QA.json file.
What is happening:
The application always uses appsettings.Production.json as default configuraiton.
Am I missing something ?
When you publish your application using dotnet publish -c QA -o deploy
, the -c QA
flag specifies that the build should use the QA configuration, but it doesn't set the ASPNETCORE_ENVIRONMENT
variable to QA
.
To achieve this in the iis you can follow below steps:
Configuration Editor
system.webServer/aspNetCore
.environmentVariables
collection, add an entry with name
as ASPNETCORE_ENVIRONMENT
and value
as QA
.after making changes the web.config will look like this:
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet" arguments=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="QA" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>