UPDATE
After writing this answer, I found out that the new way in .Net Core is to use environment variables. You can find the article here and more details here .
You can set the environment variable in the project properties in the debug section. The code will look after using DI to enter IHostingEnvironment
if (env.IsDevelopment()) {
END UPDATE
The answer @ user2095880 is valid and works. However, you may need a solution that you do not need to change project.json to go to production.
#if DEBUG app.Run(async (context) => { await context.Response.WriteAsync("Hello DEBUG CODE!"); }); #else app.Run(async (context) => { await context.Response.WriteAsync("Hello LIVE CODE!"); }); #endif
This checks the configuration of your solution (still works in .Net 5) if you are in Debug or something else. If your solution configuration is set to Debug, the first set of code will run. If you select Release (or anything else), the second section of code will be launched. See the image below for a drop-down list to go from Debugging to Release.

source share