Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core 6 how to access IWebHostEnvironment before builder.Build() in Program.cs

I want to use Environment.IsDevelopment() before builder.Build() in Program.cs. How should I do that?

 var builder = WebApplication.CreateBuilder(args);
 //Code: reach environment
 var app = builder.Build();
like image 996
nima ansari Avatar asked Sep 06 '25 00:09

nima ansari


1 Answers

You can access which environment you are currently running as by using:

builder.Environment.IsDevelopment()

Prior to the application being built at this point:

var app = builder.Build();

After this code has run you would use:

app.Environment.IsDevelopment()
like image 165
JsonStatham Avatar answered Sep 08 '25 21:09

JsonStatham