How to set environmental variable ASPNETCORE_ENVIRONMENT in IIS in the latest ASP.Net Core 1.0?
See original GitHub issueHi,
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?
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:
- Created 7 years ago
- Comments:11 (6 by maintainers)
if some one is scrolling for answer thru here , try the steps at http://stackoverflow.com/a/36836533/4879683
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?