'JetBrains rider IDE => Hosting Environment
enter image description hereI am trying to move from Visual Studio 2022 to JetBrains rider with my .NET full-stack project.
I am using Webpack for my front-end side if it gives anyone a clue (I also run the Webpack command like in my vs2002).
The problem which occurs is the HostingEnvironment.IsDevelopmentEnvironment
always returns false.
I tried to set it from the terminal with the ASPNETCORE_ENVIRONMENT=Development
command and in the configuration setting of debug mode of my project with no luck. I can't find any solution to this problem.
// different script for dev or prod
string scriptFileName = HostingEnvironment.IsDevelopmentEnvironment ? "/dist/app.entry.js" : "/dist/app.entry.min.js";
Solution 1:[1]
You're mixing up two things: ASP.NET vs. ASP.NET Core. The environment variable ASPNETCORE_ENVIRONMENT
is used by ASP.NET Core, whereas the method HostingEnvironment.IsDevelopmentEnvironment
is only part of old ASP.NET.
As you already discovered, you have to set DEV_ENVIRONMENT=1
and I see two options:
- Set environment variable system-wide
- Set environment variable within Rider configuration
1. System-wide
This implies that all consumers (your app, integration tests, etc.) use the same value, i. e. all apps are in development mode. It depends on your needs whether this is acceptable or not.
Assuming that you're working on Windows, you can either set the environment variable via GUI (see here) or CLI (see setx
command).
Keep in mind that environment variables are picked up on application startup. So you have to restart Rider after changing the variable.
2. Rider
Open the Run Configurations and configure it like this:
You have to do this for all your Run Configurations.
Solution 2:[2]
Add DEV_ENVIRONMENT=1
to your project run configuration in your JetBrains IDE.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mu88 |
Solution 2 | Jeremy Caney |