发布MVC 6 Web App时设置环境 [英] Setting Environment When Publishing An MVC 6 Web App

查看:71
本文介绍了发布MVC 6 Web App时设置环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试Dot Net Core中的开发,并且准备部署我的应用程序.现在,我已经完成了一个简单的文件发布到本地PC的操作,然后将文件复制到了远程服务器上.

I'm testing out development in Dot Net Core, and I'm up to deploying my application. For now I've done a simple file publish to my local PC, and then copied the files onto the remote server.

查看网站时,由于向我提供了缩小的文件(在视图中指定了哪个),因此我可以看到该网站正在暂存"环境或生产"环境中运行.

When I view the website, I can see that it is running in either the Staging or Production environment due to me being served minified files (Which are specified in the view).

但是,我一直在努力寻找任何文档来说明在发布时可以在何处或如何指定此环境.即使我现在必须直接编辑此设置也可以,但是似乎找不到.

However I'm struggling to find any documentation to say where or how this environment can be specified at publish time. Even if I have to edit this setting directly for now that is fine, but I can't seem to find it.

我在发布后检查过的文件(这也包括源文件,因为我刚刚通过VS2015发布时才了解DNU命令行).

Files I've checked after publish (That also includes the source files as I'm just publishing via VS2015 at the moment over getting to know the DNU commandline).

  • wwwroot/web.config
  • approot/web.cmd
  • approot/global.json
  • approot/src/myproject/project.json
  • approot/src/myproject/hosting.json
  • approot/src/myproject/project.json
  • approot/src/myproject/Properties/launchSettings.json

推荐答案

很好玩.但是,这是Windows计算机的答案.

Well that was a bit of fun. But here's the answer for a Windows machine.

该变量是系统范围的环境变量,如果您在同一台计算机上有两种不同的配置(例如我们在同一台计算机上有针对不同团队的Test1,Test2,Test3等),那么我不确定如何运行,虽然我想如果要达到这个大小,则可能会使用Chef/Puppet之类的东西来存储配置.

The variable is system wide environment variable, I'm not sure how that's going to fly if you had two different configurations on the same machine (e.g. We have Test1, Test2, Test3 etc for different teams all on the same machine), although I suppose if you are getting to that size, you might be using something like Chef/Puppet to store configurations.

如何在整个系统范围内设置变量.

How you can set the variable system wide.

  1. 右键单击我的电脑",此电脑",我的电脑"或您所打开的任何窗口上的变体.选择属性.
  2. 点击高级系统设置"(在Win10上位于左侧).
  3. 在下一个窗口的底部单击环境变量".
  4. 在系统变量"上单击新建...".然后使用您指定的环境输入"ASPNET_ENV",例如....

  1. 现在重置IIS,您应该一切顺利.

我看到其他人建议"Hosting:Environment"是新的变量名,但这对我不起作用,也许对您有用!我可以看到在launchSettings.json中它使用了宿主变量,但是当我把它放在机器范围内时,它对我不起作用.我想那是摆弄发布候选者的乐趣! :)

I have seen other people suggest that "Hosting:Environment" is the new variable name but this did not work for me, maybe it will work for you! I can see that within launchSettings.json it uses the hosting variable, but it didn't work for me when I put it machine wide. I suppose that's the the fun of fiddling with Release Candidates! :)

另一件事要注意.从Visual Studio启动时,其运行的环境保存在/Properties/launchSettings.json

Another thing to note. When launching from Visual Studio, the environment it runs in is kept in /Properties/launchSettings.json

"IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "environmentVariables": {
    "Hosting:Environment": "Development"
  }
}

您可以在此处编辑Hosting:Environment变量,以在其他环境中自动启动.

You can edit the Hosting:Environment variable here to auto launch in a different environment.

但是,当您从常规IIS运行时,默认始终为生产"(看不到出错的地方.....).

However when you run from regular IIS, the default is always "Production" (Can't see that ever going wrong.....).

这篇关于发布MVC 6 Web App时设置环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆