Aspnetcore.docs: Setting environment variable

Created on 10 May 2018  Â·  7Comments  Â·  Source: dotnet/AspNetCore.Docs

I have three profiles the only difference between the three is that I would like to set ASPNETCORE_ENVIRONMENT in the web.config. Like @Rick-Anderson edit to show code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\PocketNurse.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Omnicell" />
            </environmentVariables>
        </aspNetCore>
  </system.webServer>
</configuration>

Everytime I publish I have to edit the web.config file and add the section. I would like this to set ASPNETCORE_ENVIRONMENT to different values based on the profile that I am publishing with. Is this possible?


Document Details

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

P3 Source - Docs.ms

Most helpful comment

Thank you. Now web.config is not in the published output.

All 7 comments

@KevinBurton can you ask that on SO?

I just did. Thank you.

@KevinBurton

Everytime I publish I have to edit the web.config file

You can disable the transformation of the file on publish by adding this to your project file ...

<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>

https://github.com/aspnet/websdk/blob/dev/src/Publish/Microsoft.NET.Sdk.Publish.Targets/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets#L47

https://docs.microsoft.com/aspnet/core/host-and-deploy/iis#webconfig-file

I added this line to the project file and my project will no longer load. Visual Studio indicates that the project is "unavailable"

You put it into a PropertyGroup? ... Sorry if I didn't make that clear. Add it at the top where your target framework, etc. are located ...

<PropertyGroup>
  <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
  <TargetFrameworks>netcoreapp2.1</TargetFrameworks>
</PropertyGroup>

Thank you. Now web.config is not in the published output.

does'nt work for me
I also tried
<ANCMPreConfiguredForIIS>true</ANCMPreConfiguredForIIS>
and I get a 500 error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wgutierrezr picture wgutierrezr  Â·  3Comments

nenmyx picture nenmyx  Â·  3Comments

AnthonyMastrean picture AnthonyMastrean  Â·  3Comments

cocowalla picture cocowalla  Â·  3Comments

serpent5 picture serpent5  Â·  3Comments