Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for launchSettings.json to dotnet run #8274

Closed
danroth27 opened this issue May 17, 2017 · 21 comments
Closed

Add support for launchSettings.json to dotnet run #8274

danroth27 opened this issue May 17, 2017 · 21 comments
Milestone

Comments

@danroth27
Copy link
Member

@livarcocc @DamianEdwards @sayedihashimi @mlorbetske @richlander lander

For ASP.NET Core projects we setup a bunch of useful machinery in our templates when running in Development. Unfortunately none of this machinery gets used when doing dotnet new and dotnet run because the default environment is assumed to be Production and nothing specifies that the environment should be Development. The environment is typically specified using an environment variable (ASPNETCORE_ENVIRONMENT).

VS today uses launchSettings.json to drive the F5 experience. This file enables you to specify things like environment variables when the application is launched. You can also specify additional command-line args, and whether the browser should be launched and at what address.

We'd like to add support to dotnet run for honoring the settings in launchSettings.json. Initially we can limit this support to the "Project" command name and specifically add support for setting environement variables and command-line args. Later we can look adding support for things like specifying the application URL and launching the browser:

{
  "profiles": {
    "MyAspNetCoreProject": {
      "commandName": "Project",
      "commandLineArgs": "--name value",
      "launchBrowser": true,
      "launchUrl": "https://localhost:44316/",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:44316/"
    }
  }
}

@DustinCampbell We should also chat about having VSCode support this format

@livarcocc
Copy link
Contributor

@mlorbetske We need the parser for the file. Let me know when you have that.

@mlorbetske
Copy link
Contributor

@bricelam
Copy link
Contributor

bricelam commented May 23, 2017

👀 dotnet-ef wants to use this too. We hope the feature can light up during dotnet exec since that's how we dispatch to the dependency tool which loads the project's assembly and executes Program.BuildWebHost.

@livarcocc
Copy link
Contributor

The scope for now is to just set some environment variables before invoking the app.

@guidobouman
Copy link

guidobouman commented May 29, 2017

Passing the launchUrl wouldn't be too much work, right?

We have a project with 4 simultaneously running processes that all talk to each other in one way or another. For VS studio users on Windows this all runs smoothly. For VS code on mac we've duplicated the settings to launch.json & tasks.json. But running 4 concurrent processes in VS code crashes on launch. So we run 3 of the 4 processes in the terminal with the CLI. This gets troublesome when we need to specify the server url for each command: --server.urls http://localhost: 44316/. Mapping them from the launchUrl prop would be great.

PS: VS for mac is terribly slow, so we're not using that. Running in there kinda worked, but at the cost of waiting over 3 minutes to start the project.

@geirsagberg
Copy link

A problem I ran into is that environment variables from launchSettings.json will always override env.vars set on command line, e.g. I have "ASPNETCORE_ENVIRONMENT": "Development" in launchSettings.json, and then when I run set ASPNETCORE_ENVIRONMENT=Production && dotnet run, the environment is still development.

Maybe there should be a way to opt out of launchSettings?

@geirsagberg
Copy link

After running dotnet run --help, I noticed the switch --no-launch-profile, which does exactly what I need, so ignore my last comment :)

@adzhiljano
Copy link

Sorry for bringing this up, but I noticed this comment: https://github.com/dotnet/cli/blob/master/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs#L18
Are you going to support everything from launchSettings.json, since this PR is closed?
I wanted a browser to open when running dotnet run, but nothing happens right now, and i have "launchBrowser": true.
Thanks!

@livarcocc
Copy link
Contributor

We haven't talked about extending the support for launchSettings.json beyond what we already have. And we don't have plans to support 100% of it, as there are things there that don't make sense in the command line.

@LordMike
Copy link
Contributor

LordMike commented Dec 17, 2017

Added note on Docs page to document this new default.

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments

EDIT: probably have a higher chance of success here: dotnet/AspNetCore.Docs#5023

@Alu1994
Copy link

Alu1994 commented Jul 29, 2018

thanks @geirsagberg, i was having the same problem with my app!

@ygoe
Copy link

ygoe commented Nov 12, 2018

So commandLineArgs isn't one of the supported options? I don't know what actually is supported, I just see that "the start options from (my launchSettings.json file) are used". But command line arguments are not set in the program, nor visible in a task manager.

@jiimaho
Copy link

jiimaho commented Nov 4, 2019

Is it true that the only thing left to honor is the commandLineArgs?

@Davilink
Copy link

Davilink commented Dec 5, 2019

Is the commandLineArgs still not supported ?

@andras-gyarmati
Copy link

I would need commandLineArgs as well, please implement it!

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@philippdolder
Copy link

+1 to support commandLineArgs this is especially helpful when I want to use dotnet watch run since this will use the same settings as running it from the IDE

@cesarsouza
Copy link

+1 as well

@kotx
Copy link

kotx commented Oct 7, 2020

+1

@PooSham
Copy link

PooSham commented Feb 25, 2021

I can't believe .NET 5 is released and commandLineArgs is still not supported.

@dasMulli
Copy link
Contributor

As an alternative, you can set StartArguments in the csproj.

<PropertyGroup>
  <StartArguments>--foo bar</StartArguments>
</PropertyGroup>

@atifaziz
Copy link

atifaziz commented Mar 5, 2021

As an alternative, you can set StartArguments in the csproj.

@dasMulli Even better, set it in the user-specific project file (e.g. MyProject.csproj.user) as that will usually/hopefully be ignored in .gitignore and won't accidentally get committed to version control.

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

No branches or pull requests