question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set environmental variable ASPNETCORE_ENVIRONMENT in IIS in the latest ASP.Net Core 1.0?

See original GitHub issue

Hi,

We use VS publish option to deploy to multiple environments ( Dev, Preview and Prod), so i added below commands in project.json file to set ASPNETCORE_ENVIRONMENT value dynamically in the web server as part of publish script. (This was setting environmental variable located in appsettings part of my web.config on my website in IIS). I was doing this to avoid a manual job of setting this ASPNETCORE_ENVIRONMENT variable in each deployment server

Things were working fine with RC2 libraries but it started failing with latest 1.0 libraries. After analysis, i figured out that there was a environmentalvariables element in system.webServer/aspNetCore section of web.config in IIS (Accessed through ConfigurationEditor) and that was not set and hence our code was failing when we check Environment.IsDevelopemnt() function.

What is the command that i can use in project.json to set environmental variable (ASPNETCORE_Environment) in that path while publishing?

image

Project.Json: (Snippet)

 "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "commands": {
    "Development": "Microsoft.AspNet.Server.Kestrel --ASPNETCORE_ENVIRONMENT Development",
    "Preview": "Microsoft.AspNet.Server.Kestrel --ASPNETCORE_ENVIRONMENT Preview",
    "Production": "Microsoft.AspNet.Server.Kestrel --ASPNETCORE_ENVIRONMENT Production"
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }

Thanks,

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

16reactions
Elrashidcommented, Aug 11, 2016

if some one is scrolling for answer thru here , try the steps at http://stackoverflow.com/a/36836533/4879683

8reactions
oliverjanikcommented, May 1, 2017

This answer is completely unsatisfactory. Why are web.config transforms disabled for ASP.NET Core projects?

If I want to have have ASPNETCORE_ENVIRONMENT per site in IIS I have to do it in web.config right? How do I transform the config? Nope.

This dependency on a shared global env variable for every site that’s deployed on a server is complete rubbish when it comes to IIS deployments. I understand you’re trying to be platfor agnostic but the dev experience of deploying to IIS is utter confusion.

For example: how do you suggest I add this rewrite rule for production?

        <rewrite>
            <rules>
                <rule name="HTML5" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/" />
                </rule>
            </rules>
        </rewrite>
Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net core - Publish to IIS, setting Environment Variable
Go to your application in IIS and choose Configuration Editor . · Select Configuration Editor · Choose system. · Choose Applicationhost. · Right ......
Read more >
ASPNETCORE_ENVIRONMENT Variable in ASP.NET Core
Go to Control Panel -> System -> Advanced System Settings -> Environment Variables. You will see the following screen. Add the Variable either ......
Read more >
Use multiple environments in ASP.NET Core
To set the ASPNETCORE_ENVIRONMENT environment variable with web.config , see the Set environment variables section of web.config file. Windows - ...
Read more >
How to setup ASPNETCORE_ENVIRONMENT variable on an ...
Open the "Internet Information Services (IIS) Manager. · Go to the Website where you want to set the environment variable. · Find the...
Read more >
How to set environmental variable ...
Hi, We use VS publish option to deploy to multiple environments ( Dev, Preview and Prod), so i added below commands in project.json...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found