How to set aspnetcore_environment in publish file?
<p>I have ASP.NET Core application (Web Api). The documentation has explained <a href="https://docs.asp.net/en/latest/fundamentals/environments.html" rel="noreferrer">working with multiple environments</a>, however it failed to explain how to set <code>aspnetcore_environment</code> when publishing the web site.     </p>

<p>So lets say if i have 3 environments <code>Development</code>, <code>Staging</code> and <code>Production</code>   </p>

<ol>
<li><p>In classic ASP.NET Web Application i used to create 3 build configurations. <code>Development</code>, <code>Staging</code> and <code>Production</code> ( Like shown in picture below).  and then 3 <code>.pubxml</code> files, one for each configuration. Do i need to use the same approach for <code>ASP.NET Core</code> application as well?</p></li>
<li><p>How do i set <code>aspnetcore_environment</code> in <code>.pubxml</code> file?  </p></li>
<li><p>If the approach specified in Question 1 is obsolete, then what's the alternate approach? ( I use Jenkins for CI)</p></li>
</ol>

<p><a href="https://i.stack.imgur.com/8K8Zs.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8K8Zs.png" alt="enter image description here"></a></p>

<p><strong>Update 1</strong></p>

<p>I understand that I have to set <code>ASPNETCORE_ENVIRONMENT</code> however I am not able to understand where do we set this? During development I can set this in profile in <code>launchSettings.json</code>, however question was how do we set this when publishing to staging or production? do we set environment variable on the target server itself? </p>

<p><a href="https://i.stack.imgur.com/55kOO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/55kOO.png" alt="enter image description here"></a></p>

<p><strong>Update 2</strong><br>
I found article <a href="http://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/" rel="noreferrer">here</a> that explains different ways of setting environment variable. This partially answered my question. However when I publish the application, the publish process does not honor the environment variable while publishing <code>appsettings.{env.EnvironmentName}.json</code><br>
I have created separate <a href="https://stackoverflow.com/questions/39256057/how-to-publish-environment-specific-appsettings-in-net-core-app">post</a> for that question</p>