-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Environment variables defined in tasks.json::tasks.options.env
do not overwrite existing environment variables
#47985
Comments
Since this is a shell task the bash decides to source The shell started has the -c option so the shell source
at its being. So every instructions you have after that are not executed if the -i option is not present. So I recommend that you move the environment variables into OK to close |
NOT ok to close. How is VSCode setting the environment variables I request in |
It is setting the environment for the launched shell process. Tasks don't start login shells so the |
Do you have a Mac to reproduce this with? Use To reproduce:
The value from |
@zfields I understand the problem and it is independent of the OS at the end. Since VS Code doesn't want to temper with what shells do when executed you can't override any variables that are later on sourced from somewhere else. I tested this and |
I think we are talking past each other, maybe we should take two steps back... I have no desire to use a shell. In fact, I ONLY want to use VSCode. However, when running a "shell task" in VSCode (i.e. I think we need to make sure we are experiencing the same behavior, before we can attempt to solve this problem. |
I tried this on Apple and Linux and in both cases the |
I'm sorry, I am completely confused. I am not trying (and do not wish) to use any shell whatsoever, I am only trying to use the "tasks" detailed by Your directives about running bash with different parameters and using different shells make no sense to me - unless those are options that need to be entered into the Can you deliberately spell out what you mean by "this" in the following sentence?
Meanwhile, I will try to shutdown my machine completely. Only open VSCode and no other applications, and see if the environment variables listed in Futhermore, I WILL NOT be opening a shell (deliberately), unless it is done so on my behalf, without my knowing, by VSCode or macOS. |
Just to confirm...
How is this happening, if executing a task from the UI in VSCode is not loading environment varialbes from |
If you create a tasks of type |
No, I wasn't aware the setting existed, so any behavior is the default behavior of VSCode. Following on, does it stand to reason that VSCode does in fact consume If so, are you able to inject the environment variables I have supplied in |
tasks.json::tasks.options.env
do not overwrite existing environment variables
I haven't heard anything in a few days, and the issue is still marked as "needs more info". I just wanted to make sure you are not waiting on me. |
Sorry, we are in end game. If you want to inject something into the shell the best is to build a command that does both. For example 'set X="abc" & myCommand'. What happens when you open an integrated terminal and execute printenv in it. Does it source things from the profile as well. |
Yes.
What is the point of specifying It seems like I have identified a bug for you, and you have identified a solution. However, you are suggesting that I hack it in place, instead of VSCode correctly assembling the command string by prepending the setting of environment variables to the specified To use your example, VSCode is taking a command string from me, and also has all the environment variables I wish to have set.
Why isn't VSCode capable of constructing the following string on my behalf, before passing
|
What is the best way to set new env var and or overwrite existing PATH var required only for test build on machine without admin rights? .NET classic is used |
This is really strange since values from the profile should only be sourced when We don't inject something into the shell to keep it consistent with the process type were we can't do such tricks and rely on what the process sees when executed. I will keep the item open to consider it as a feature request to treat this different for |
@hellboy81 usually you should be able to overwrite the PATH by specifying the |
Did you mean "your" machine? If so, then no, I have not.
Do you mean " |
Based on my experience thus far, I would not expect @hellboy81 to be able to overwrite an existing environment variable (i.e. |
I meant your machine. I read a little bit more about it and it looks like under MacOS it depends on which terminal is used whether the |
I've lost your train of thought. Can you take a moment to explain what the results of your |
Sorry for the short answer. Normally bash defines that |
@zfields thanks a lot for testing this. I will look into why some of the behavior is unexpected. Regarding 2.) this is expected in the sense that things from
from the beginning however then exports from the Can you let me know in terms of variables which once you want to define were and which once should win? |
My expectation is as follows. If I am defining environment variables in Specifically, It would be great if I could simply override |
This should actually work by having the default |
Can this be related to Runtime Protections? BTW the one mentioned by @zfields is the desired feature for most vscode users: it would be great if I could simply override DYLD_LIBRARY_PATH in the task, so I can develop and debug without modifying my file system. |
In this case the easiest is for now to have a task command line that sets |
Some more digging here with our Mac expert and here is a workaround for now: in the task that wants to override the environment variable add the following:
Let me know if this fixes the problem for you. If so I can make a change in VS Code itself that doesn't make this necessary anymore. |
Task:
Results in:
If I remove the
|
@zfields thanks. The error comes from the fact that VS Code couldn't find bash. Can you make it an absolute path and retry. And can you check if this then lets you replace the |
I modified
Result:
Observations:
|
Actually that puzzles me. You can override With the workaround of specifying the shell there is actually no need anymore to have a Just to check: does the
|
I double checked and match exactly on the I have remerged --- After reboot --- There is no difference between the way I specify Still missing In VSCode (
In VSCode (TERMINAL):
|
If you don't override it in the env will the task print the value correctly that is specified in |
No, it doesn't. Removing the override:
However, if I press "Enter" to close the task terminal and fall back to the terminal in VSCode, then I copy/paste the command string from above and get these results:
|
I will test this again on a Mac. I have to admit that I have no idea what makes |
May not be 💯% related to the above, although I stumbled upon this and found This is what worked for me:
Hope it helps someone else! 🎉 |
Should this work the same on Windows? I have the following task:
and get the following output:
Not sure why $message is not expanded to the environment variable that is being set. |
@jwmurray Please open a separate issue for your experience, as it is not directly related to this issue. This issue is still open / under investigation, and it took forever for the bug listed above to be recognized and confirmed by Microsoft. I'm sorry to shut you down, but there has been enough confusion on this thread. @dbaeumer It has been several months since you were going to test again on your Mac, and I am curious if you have been able to land on a solution. |
I will reactive my Mac and will have a look beginning of next week. |
This issue and the handling of "env" options in
Results (without FOO or BAR set/exported in the parent shell that executes
Results (with set/exported FOO=foo BAR=bar in the parent shell that executes
Tested with Visual Studio Code 1.31. Bottom line is:
Is this a bug or by design?? FWIW, I would prefer if If not a bug, would that be a feature request? |
This deserves reconsideration. Yes, I know the value that's going to be expanded, but I'd like to not check this value into source code. I'd really like the ability to run tasks with arguments passed from |
Generally speaking, env vars set in task |
I can confirm this works as expected now, and the point of this original issue has been resolved to my satisfaction. Thank you! |
Code: 1.22.2
macOS: 10.13.3
When I create a task, I want to provide a very specific environment (which is why I bother filling out the JSON values). However, if an environment variable is pre-existing, it will not be overwritten in the execution environment of the task.
I am extremely surprised by this behavior. I discovered this by not being able to find a library I was building with a task when specifying
DYLD_LIBRARY_PATH
.A very simple test is to update
~/.bash_profile
to includeThen attempt to override it with
tasks.json
Output:
A "task" appears to execute
. ~/.bash_profile
to set it's environment. Since it is already creating a new environment for each execution, it would be nice if I could override the values as I see fit, by specifying the values intasks.options.env
.The text was updated successfully, but these errors were encountered: