Çevreyi bulmak için ASPNETCORE_ENVIRONMENT
(Eskiden ASPNET_ENV
RC1 modelinde) ortam değişkenini kullanabilirsiniz. Bu process.env.ASPNETCORE_ENVIRONMENT
kullanarak gulpfile yapılabilir.
Ortam değişkeni yoksa Visual Studio'nun uygulamanızı başlatmak için kullandığı launchSettings.json
dosyasını okuyabilirsiniz. Bu da yoksa, Geliştirme ortamını kullanmaya geri dönüş.
gulpfile.js dosyasındaki ortamı daha kolay hale getirmek için aşağıdaki JavaScript nesnesini yazdım. Tam gulpfile.js kaynak kodunu here bulabilirsiniz.
// 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; }
};
ortam değişkeni nasıl ayarlanacağı için this yanıta bakın.
Bu, RC1'de sıfırdır ve bu nedenle çalışmıyor ve hala mevcut yapılandırmamızı bize vermiyor. –
ASPNET_ENV değişkenini Windows/Linux/Mac OS'nuzda ayarlamanız gerekir. Buna bakın: https://stackoverflow.com/questions/32301840/how-to-set-asp-net-5-environment-variables-on-production-environment/32326666#32326666 –
Ayrıca, bu ortam değişken adının da değiştiğine dikkat edin. RC2'de. –