@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
@mlorbetske We need the parser for the file. Let me know when you have that.
So far, the logic of interest is split across the three files below - it seems pretty integrated with CPS. Most of the entanglement seems to be in relation to managing the file (updates in the VS UI) and orchestrating VS events.
The particular section relevant to reading the file is here - it delegates obtaining the types to deserialize as to the components that handle the different sections:
https://github.com/dotnet/project-system/blob/master/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs#L380-L409
The portion that applies the environment variables & such for the project type launch profile is here:
https://github.com/dotnet/project-system/blob/master/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Debug/ConsoleDebugTargetsProvider.cs#L174-L267
馃憖 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
.
The scope for now is to just set some environment variables before invoking the app.
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.
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?
After running dotnet run --help
, I noticed the switch --no-launch-profile
, which does exactly what I need, so ignore my last comment :)
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!
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.
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: https://github.com/aspnet/Docs/issues/5023
thanks @geirsagberg, i was having the same problem with my app!
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.
Is it true that the only thing left to honor is the commandLineArgs
?
Is the commandLineArgs still not supported ?
I would need commandLineArgs as well, please implement it!
+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
+1 as well
+1
Most helpful comment
After running
dotnet run --help
, I noticed the switch--no-launch-profile
, which does exactly what I need, so ignore my last comment :)