简体   繁体   中英

Cannot set my Environment Variable to Development in Asp.NET CORE

My launchSettings.json is:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:65000",
      "sslPort": 44367
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Portal.WebUI": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

Also when I right click to my Web Project in Solution Explorer my ASPNETCORE_ENVIRONMENT is set to Development.

But there is an issue,

In my startup

if (env.IsDevelopment())
{
}                            }
else{
}

when I put a debugger here, it goes to "else" block as if it is not set to Development environment.

So I tried another way of debugging it, and I think I know the error, but I dont know why it is happening.

So I put a line of code above my "if/else" condition which is:

var envi = env.EnvironmentName;
if (env.IsDevelopment())
 {      
 }
 else
{
}

So when I put my debugger point to "var envi" line, then "envi" variable comes "Development;Development;" but it should be only "Development".

EDIT

Now, I tried to change it to Production from right clicking to my project and set ASPNETCORE_ENVIRONMENT to "Production" now my "envi" variable is "Development;Production"

So always there is a "Development;", how can I find the issue in here..

Can you please help?

Visual Studio caches the environment variables when it was started up - not when you hit "debug", so you may want to restart the IDE and give it one more try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM