Consider adding 'development' as default environment #1394

Closed
opened 2025-08-09 17:19:58 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @MrCrimp on 9/9/2016

By adding a overridable default environment in program, I was able to solve two issues when developing further on the react-redux template generated by yeoman.

Running dotnet runwithout arguments from the command line.

Compiling WebClient for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)

Hosting environment: development

As you see, running in development but the result is webpack was unable to build the main.js file, resulting in a consistent Status 404 for the file wwwroot/dist/main.js

Trying to run the command `ẁebpack`` to manually produce the dist/main.js file solved the 404 problem but then HMR was completely broken.

Note that this dit not occur on any of the two platforms when starting from Visual Studio (IISExpress) or VsCode (using default launch settings)

  • OSX: dotnet run required ASPNETCORE_ENVIRONMENT to be set everytime explicit e.g
    ASPNETCORE_ENVIRONMENT=Development dotnet run. This seems to be default dotnet CLI behaviour.
  • Windows: I was unable to pin down when dotnet run stopped working without setting environment explicitly. Probably an easy fix but I was unable to find a working equivalent setenv for windows that was picked up further down (webpack?), tried most approaches like

Set ASPNETCORE_ENVIRONMENT=development

or

dotnet run environment=development

Not sure if I overlooked some obvious solution but the working solution for me was this:


            var defaults =
                new Dictionary<string, string> {
                    { WebHostDefaults.EnvironmentKey, "development" }
                };

            var config = new ConfigurationBuilder()
                .AddInMemoryCollection(defaults)
                .AddCommandLine(args)
                .AddEnvironmentVariables(prefix: "ASPNETCORE_")
                .Build();

*Originally created by @MrCrimp on 9/9/2016* By adding a overridable default environment in program, I was able to solve two issues when developing further on the react-redux template generated by yeoman. Running `dotnet run`without arguments from the command line. > Compiling WebClient for .NETCoreApp,Version=v1.0 > Compilation succeeded. > 0 Warning(s) > 0 Error(s) > > Hosting environment: development As you see, running in _development_ but the result is webpack was unable to build the main.js file, resulting in a consistent Status 404 for the file **wwwroot/dist/main.js** Trying to run the command `ẁebpack`` to manually produce the dist/main.js file solved the 404 problem but then HMR was completely broken. Note that this **dit not** occur on any of the two platforms when starting from Visual Studio (IISExpress) or VsCode (using default launch settings) - OSX: dotnet run required ASPNETCORE_ENVIRONMENT to be set everytime explicit e.g `ASPNETCORE_ENVIRONMENT=Development dotnet run`. This seems to be default dotnet CLI behaviour. - Windows: I was unable to pin down when `dotnet run` stopped working without setting environment explicitly. Probably an easy fix but I was unable to find a working equivalent setenv for windows that was picked up further down (webpack?), tried most approaches like `Set ASPNETCORE_ENVIRONMENT=development` or `dotnet run environment=development` Not sure if I overlooked some obvious solution but the working solution for me was this: ``` csharp var defaults = new Dictionary<string, string> { { WebHostDefaults.EnvironmentKey, "development" } }; var config = new ConfigurationBuilder() .AddInMemoryCollection(defaults) .AddCommandLine(args) .AddEnvironmentVariables(prefix: "ASPNETCORE_") .Build(); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1394
No description provided.