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

[dotnet-run] Allow overriding launch profile environment variable values #45740

Open
tmat opened this issue Jan 6, 2025 · 6 comments
Open

[dotnet-run] Allow overriding launch profile environment variable values #45740

tmat opened this issue Jan 6, 2025 · 6 comments
Assignees
Labels
Area-CLI needs team triage Requires a full team discussion untriaged Request triage from a team member
Milestone

Comments

@tmat
Copy link
Member

tmat commented Jan 6, 2025

dotnet run -lp Profile uses env variables from the specified profile and ignores the values set in the current environment.
This is true even when the environment variable is explicitly set via an environment directive, e.g. dotnet [env:X=Y] -lp Profile.
As a result, there is no way to override an environment variable value set in the profile.

dotnet-watch launches projects via dotnet run. When invoked by Aspire DCP server it needs to implement Aspire launch profile semantics, which require any explicitly specified environment variable value to override the value in the launch profile. To implement this protocol correctly we need to be able to invoke dotnet run with specified env variable values overridden.

Possible options:

  • change run to only set env vars from the LP if there isn't a value already set in the executing environment [breaking change]
  • change run to only set env vars from the LP if there isn't a value already set in the by [env:X=Y] directive [less breaking]
  • change run to have a new -e/--environment KEY=VALUE option that can be used to override the value [almost not breaking]

Note:
Command line arguments passed explicitly on dotnet run command line override those specified in launch profile. This is the desired behavior and it seems environment variables should behave the same way.

Related env variable directive issue:
#40484

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Jan 6, 2025
@tmat
Copy link
Member Author

tmat commented Jan 6, 2025

@tmat tmat added this to the 9.0.2xx milestone Jan 6, 2025
@baronfel baronfel self-assigned this Jan 7, 2025
@baronfel baronfel added the needs team triage Requires a full team discussion label Jan 7, 2025
@marcpopMSFT
Copy link
Member

Triage
We discussed the various options proposed and while many would work, they would require creating new concepts. We think the -e CLI option for run makes the most sense as it aligns with dotnet test which already has that command as well as other ecosystems that have a similar option.

@tmat Chet said you were willing to potentially implement this. Is this something you were willing to take on? The environment part is probably straight forward but the trick here would be ensuring that the launch profile doesn't override a value specified by the -e option.

@tmat
Copy link
Member Author

tmat commented Jan 7, 2025

I can give it a try and see if I can figure it out.

@tmat
Copy link
Member Author

tmat commented Jan 7, 2025

If we go with -e what's the purpose of env directives? Should we make them obsolete?

@baronfel
Copy link
Member

baronfel commented Jan 7, 2025

We get them for free from S.CL and I believe other teams have used them in the past (we had bugs logged a couple years ago where an S.CL update accidentally removed them and teams screamed). This -e is just a more clear/surfaced in help way that we can more concretely control.

@tmat
Copy link
Member Author

tmat commented Jan 7, 2025

OK. Just seems odd to have 2 features that do similar things but are different in subtle ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI needs team triage Requires a full team discussion untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants