Docs: Setting environment using dotnet publish command

Created on 10 Oct 2019  Â·  4Comments  Â·  Source: dotnet/docs

Hi
I have a couple of questions:

  1. Is it possible to set environment when publishing with dotnet publish like dotnet publish --environment "Development" or no? if yes how?
  2. Is it possible to ignore project warnings when publishing with dotnet publish?

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Area - .NET Core Guide Technology - CLI product-question

Most helpful comment

In case anyone arrives here looking to transform their web.config via dotnet publish, you can do this with (for example):

dotnet publish -o site /p:EnvironmentName=Staging

Adds the following to your web.config in the publish directory:

<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Staging" />

All 4 comments

Hello!

I'm not sure what you mean by environment do you mean the --configuration switch for Debug or Release?

Project warnings should not prevent you from publishing. Project errors would.

Hi again
Excuse me for not being enough clear.
By the term environment I mean ASPNETCORE_ENVIRONMENT environment variable or generally any environment variable.
And I know that warnings are not prevent the build or publish process but I want them to be hide so I can get more concentrated info

No worries!

To hide the warnings, try passing this switch to MSBuild (which is what the dotnet publish command uses) stackoverflow question/answer

/p:WarningLevel=0

Environment variable, no. Since environment variables are consumed by your app but set by the host, you need to configure the host some how. For example, if you're going to deploy to the cloud, the cloud provider usually has an option to set the environment variables for your app. If you're deploying to someone's machine, you might want to supply as startup script for them to run. You can have your app detect the value of that variable and then output an error if it's not what you're expecting.

I think your questions are answered. I'm going to close this issue. Thanks!

In case anyone arrives here looking to transform their web.config via dotnet publish, you can do this with (for example):

dotnet publish -o site /p:EnvironmentName=Staging

Adds the following to your web.config in the publish directory:

<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Staging" />

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LJ9999 picture LJ9999  Â·  3Comments

stanuku picture stanuku  Â·  3Comments

gmatv picture gmatv  Â·  3Comments

ike86 picture ike86  Â·  3Comments

skylerberg picture skylerberg  Â·  3Comments