Search code examples
asp.net-corepublishstaging

dotnet publish /p:EnvironmentName=Staging not work


I tried to publish my ASP.NET 5 solution via

dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false /p:DebugType=None /p:DebugSymbols=false /p:EnvironmentName=Staging

that found here.

But I still see in logs that EnvironmentName is Production. What did I do wrong?

I also tried to add

<PropertyGroup Condition=" '$(Configuration)' != '' AND '$(Configuration)' != 'Debug' ">
    <EnvironmentName>'$(Configuration)'</EnvironmentName>
  </PropertyGroup>

into WebApp .csproj, but the result is the same - nothing changes.


Solution

  • This approach is valid only if you deploy your application on IIS (docs).

    Based on your publish command

    dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false /p:DebugType=None /p:DebugSymbols=false /p:EnvironmentName=Staging

    You are building it for ubuntu.18.04-x64, therefore you will not be using IIS. To change the EnvironmentName on Linux you will have to do one of the following:

    1. Setup env variable ASPNETCORE_ENVIRONMENT=Staging.
    2. Send enviroment as cli argument when you run the application :" dotnet .\webapi.dll environment=staging