Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何确定my Gulpfile.js中的ASP.NET核心环境_Gulp_Asp.net Core_Production Environment_Visual Studio 2015_Asp.net Core Mvc - Fatal编程技术网

如何确定my Gulpfile.js中的ASP.NET核心环境

如何确定my Gulpfile.js中的ASP.NET核心环境,gulp,asp.net-core,production-environment,visual-studio-2015,asp.net-core-mvc,Gulp,Asp.net Core,Production Environment,Visual Studio 2015,Asp.net Core Mvc,我正在使用Visual Studio 2015使用ASP.NET核心MVC 6。在我的gulpfile.js脚本中,我想知道托管环境是开发环境、暂存环境还是生产环境,这样我就可以添加或删除源映射(.map文件)并执行其他操作。这可能吗 更新 有关的问题。您需要在每个环境中设置NODE_ENV环境变量,然后在gulpfile中,使用process.ENV.NODE_ENV读取该变量 查看更多详细信息。您可以使用ASPNETCORE\u环境(以前是RC1中的ASPNET\u ENV)环境变量来获取环

我正在使用Visual Studio 2015使用ASP.NET核心MVC 6。在我的gulpfile.js脚本中,我想知道托管环境是开发环境、暂存环境还是生产环境,这样我就可以添加或删除源映射(.map文件)并执行其他操作。这可能吗

更新


有关的问题。

您需要在每个环境中设置NODE_ENV环境变量,然后在gulpfile中,使用process.ENV.NODE_ENV读取该变量


查看更多详细信息。

您可以使用
ASPNETCORE\u环境
(以前是RC1中的
ASPNET\u ENV
)环境变量来获取环境。这可以使用
process.env.ASPNETCORE\u环境在gulpfile中完成

如果环境变量不存在,您可以回过头来读取Visual Studio用于启动应用程序的
launchSettings.json
文件。如果这也不存在,那么回退到使用开发环境

我编写了以下JavaScript对象,以便更轻松地处理gulpfile.js中的环境。您可以找到完整的gulpfile.js源代码


有关如何设置环境变量的信息,请参见答案。

因此,必须设置节点环境和ASP.NET 5环境才能使其正常工作。是否可以基于ASP.NET 5宿主环境设置节点环境?我不了解Visual Studio,因为我从未使用过它,但这取决于如何运行gulp任务。VS是否有某种嵌入式节点环境,您可以在其中运行gulp任务?如果是这样,我会查看偏好。如果仅从命令行运行gulp任务,则必须设置操作系统级环境变量。问题是我不需要环境,或者至少我希望能够设置每个构建配置(调试、发布等)的环境变量,以便在为演示环境构建时,我知道它将进入演示环境,API的url将在我们的Angular应用程序中相应地设置。现在我没有办法部署到特定的环境,也没有办法在部署重写配置之前在web浏览器中用javascript可读。除了从web.config或其他方式进行上下文设置外,我无需使用mvc。这在RC1中为空,因此不起作用,并且仍然无法提供当前配置。您需要在Windows/Linux/Mac操作系统中实际设置ASPNET_ENV变量。请参见:请注意,此环境变量名称在RC2中正在更改。请注意,您的回答要求我在部署之前设置环境变量,但因为VS.net中的环境变量为项目设置了一次,并且您无法根据发布目标或生成配置设置它,您不可能完成问题中需要的操作,这是一个主要问题,因为您无法使用API的正确路径部署angular,因为它目前以自动方式重写(使用gulp.replace或任何其他方式)API Uri。此
过程
变量来自何处。。。我在我的
gulpfile.js中没有看到它的定义
// Read the launchSettings.json file into the launch variable.
var launch = require('./Properties/launchSettings.json');

// Holds information about the hosting environment.
var environment = {
    // The names of the different environments.
    development: "Development",
    staging: "Staging",
    production: "Production",
    // Gets the current hosting environment the application is running under.
    current: function () { 
        return process.env.ASPNETCORE_ENVIRONMENT ||
            (launch && launch.profiles['IIS Express'].environmentVariables.ASPNETCORE_ENVIRONMENT) ||
            this.development;
    },
    // Are we running under the development environment.
    isDevelopment: function () { return this.current() === this.development; },
    // Are we running under the staging environment.
    isStaging: function () { return this.current() === this.staging; },
    // Are we running under the production environment.
    isProduction: function () { return this.current() === this.production; }
};