I'm trying to change my asp.net core hosting environment to development. What I already did is :
Run this command:
set ASPNETCORE_ENVIRONMENT=Development
Change the environment variables in system:
Run these commands:
dotnet restore
dotnet watch run
I just see in the projectName.csproj file there is comment that say that it run the production, maybe that's the problem.
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />
But for now what I see in my project is Hosting environment : Production and I want to change it to environment because I can't see the changes in live when I change client side changes like HTML, CSS.
If you need to check whether the application is running in a particular environment, use env. IsEnvironment("environmentname") since it will correctly ignore case (instead of checking if env. EnvironmentName == "Development" for example).
To set the ASPNETCORE_ENVIRONMENT environment variable in windows, run this command in cmd:
setx ASPNETCORE_ENVIRONMENT "Development"
Or
Use try in web.config
like:
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyApplication.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
After setting the ASPNETCORE_ENVIRONMENT
variable for your system you must open a new command window before running dotnet run
.
Environment variables are cached for the lifetime of the shell, so an existing window won't pick up changes to the environment variable
I wrote a post on how to achieve this here: https://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/#atthecommandline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With