It seems that Preprocessor Directives (#if DEBUG
) and ASP.NET Core Environment Name (IHostingEnvironment.EnvironmentName
) both could be used when you want to have different behavior in debug/development and release/production. When is it appropriate to use one over the other is there any reason to prefer one over the other
Example with #if DEBUG
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
#if DEBUG
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
#else
app.UseExceptionHandler("/Error");
#endif
}
Example with env.IsDevelopment()
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Error");
}
}
Update: This question I am looking for when should use the ASP.NET Core environment name (a new feature of .NET core). This is different then the other question regarding #if and conditional attribute
ConditionalAttribute
does result in compile-time alterations, whileIHostingEnvironment.IsDevelopment
does not. – Arnitaarno