Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Consider adding 'development' as default environment #302

Closed

Description

@MrCrimp

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();

Activity

  1. SteveSandersonMS commented on Sep 13, 2016

    @SteveSandersonMS
    Member

    Apologies if I'm being slow, but I'm struggling to understand what issue you're reporting.

    Could you phrase this as a set of repro steps, starting with creating a new project?

    I ask because it's not clear to me what you've done up to the point where you're reporting this. For example, if you're getting a 404 for dist/main.js, then it seems like you might have deleted that file (because the Yeoman generator creates it as part of generating a new project). I'm unsure whether or not you've also deleted other files from dist/. But then, since you mention that you're running in development mode, the default behavior is to enable Webpack dev middleware, which would autogenerate dist/main.js on demand. So altogether, I'm not following what your scenario is. Could you supply repro steps? Thanks!

  2. MrCrimp commented on Sep 13, 2016

    @MrCrimp
    Author

    It was rather a suggestion to "streamline the development experience" by ensuring the project output from the yeoman generator by default runs with
    ASPNETCORE_ENVIRONMENT=Development
    unless anything else is specified, since one of the objectives with the generator output I guess is to minimize the dev tooling pain for these type of projects.

    Main issue is:
    If I for any reason fail/forget to set environment to 'Development' explicitly when using dotnet run then webpack-dev-server fails to serve me dist/main.js on-demand.

    VsCode and Visual Studio sets the environment explicitly to Development as part of the run/debug task when using the "F5 experience".

    Another thing I noticed: on Windows I can run cmd.exe as an administrator and then do 'dotnet run' on the same project and not having to set the environment to 'Development' explicitly. This goes for others in my team as well. But that's probably another issue, for another dotnet team.

  3. simeyla commented on Jun 25, 2017

    @simeyla

    I think the issue here is that many people using your templates are new to dotnetcore and something like setting the environment isn't something second nature (it isn't just like selecting Debug / Release from a dropdown).

    After a couple google searches you're left wondering "Am I supposed to use launchsettings.json?", "Why doesn't SET ASPNETCORE_ENVIRONMENT=Development" do anything? and "Why isn't development the default for a 'template' in the first place?"

    I don't see anywhere where you actually explain this. I think a couple quick lines saying "before you run dotnet run you need to set your environment to development..."

    What caught me out was I'm using powershell and that requires me to use $env:ASPNETCORE_ENVIRONMENT="Development" - which is easy when you know it but just one of the fifty billion things you need to re-learn when starting off with angular2... and then blink... I mean Angular 4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions