I have updated my ASP.NET 5 project to beta 8, and we are now supposed to the following web command
我已将我的ASP.NET 5项目更新为beta 8,现在我们应该使用以下web命令
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
Now i have updated my project with the environment variables.
现在我用环境变量更新了我的项目。
This has also updated my launchSettings.json file, as so
这也更新了我的launchSettings.json文件
{
"profiles": {
"web": {
"commandName": "web",
"environmentVariables": {
"ASPNET_ENV": "Development"
}
}
}
}
But for some reason, every time I run the command dnx web
it says that the hosting environment is Production. Why is it not starting in development mode?
但出于某种原因,每次我运行命令dnx web时都会说主机环境是Production。为什么不在开发模式下启动?
3 个解决方案
#1
13
The settings in launchSettings.json
are only used by VS. If you run from a console, you have to set that environment variable manually.
launchSettings.json中的设置仅供VS使用。如果从控制台运行,则必须手动设置该环境变量。
CMD:
set ASPNET_ENV=Development
dnx web
PS:
$env:ASPNET_ENV=Development
dnx web
#2
1
Adding to @Victor Hurdugaci answer, you could also avoid "messing" with current environment by passing needed variables on command line.
添加到@Victor Hurdugaci答案,您还可以通过在命令行上传递所需的变量来避免“弄乱”当前环境。
Inside project.json
file, say that you have a web-dev
command specific for development environment:
在project.json文件中,假设您有一个特定于开发环境的web-dev命令:
"commands": {
"web-dev": "Microsoft.AspNet.Server.Kestrel
--ASPNET_ENV Development --Hosting:Environment Development
--config hosting.Development.json",
},
where you can see how both ASPNET_ENV
, Hosting:Environment
are set, as well as invoking a specific hosting.json
configuration.
NOTE: command is split on several lines just for readability, join again before actually pasting in JSON file.
在那里你可以看到如何设置ASPNET_ENV,Hosting:Environment,以及调用特定的hosting.json配置。注意:为了便于阅读,命令分为几行,在实际粘贴JSON文件之前再次连接。
#3
0
The command: set ASPNET_ENV=Development
is now obsolete instead you can use CMD:
命令:set ASPNET_ENV = Development现已过时,您可以使用CMD:
set ASPNETCORE_ENVIRONMENT=Development
#1
13
The settings in launchSettings.json
are only used by VS. If you run from a console, you have to set that environment variable manually.
launchSettings.json中的设置仅供VS使用。如果从控制台运行,则必须手动设置该环境变量。
CMD:
set ASPNET_ENV=Development
dnx web
PS:
$env:ASPNET_ENV=Development
dnx web
#2
1
Adding to @Victor Hurdugaci answer, you could also avoid "messing" with current environment by passing needed variables on command line.
添加到@Victor Hurdugaci答案,您还可以通过在命令行上传递所需的变量来避免“弄乱”当前环境。
Inside project.json
file, say that you have a web-dev
command specific for development environment:
在project.json文件中,假设您有一个特定于开发环境的web-dev命令:
"commands": {
"web-dev": "Microsoft.AspNet.Server.Kestrel
--ASPNET_ENV Development --Hosting:Environment Development
--config hosting.Development.json",
},
where you can see how both ASPNET_ENV
, Hosting:Environment
are set, as well as invoking a specific hosting.json
configuration.
NOTE: command is split on several lines just for readability, join again before actually pasting in JSON file.
在那里你可以看到如何设置ASPNET_ENV,Hosting:Environment,以及调用特定的hosting.json配置。注意:为了便于阅读,命令分为几行,在实际粘贴JSON文件之前再次连接。
#3
0
The command: set ASPNET_ENV=Development
is now obsolete instead you can use CMD:
命令:set ASPNET_ENV = Development现已过时,您可以使用CMD:
set ASPNETCORE_ENVIRONMENT=Development