-
Notifications
You must be signed in to change notification settings - Fork 903
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
Refreshenv should expand variables recursively in case they're new (includes solution) #1417
Comments
I think you may want to be sure you are running refreshenv for PowerShell amd not the batch script. Key indicator? Note that it said it was running refreshenv for cmd.exe |
So maybe ensure the Chocolatey PowerShell profile is installed first and see if it already does the right thing? |
The refreshenv.bat you saw it running in your output would never have any effect on PowerShell because it needs to start a subprocess to apply that batch, and those changes go away when that subprocess exits. |
Ah thanks, I think you're right that in my minimized test case I ended up calling the batch version accidentally. Because there's an alias set up I had assumed I was running that, but it probably wasn't imported. I'll post the output with the the PowerShell cmdlet tomorrow |
👍 |
I've edited the original post (which used to incorrectly use refreshenv.bat) and replaced it with the powershell output so the comments before here won't make total sense any more |
This got stuck in triaging a long time ago. Is there anything I can do to move it forwards? Would it help if I make a PR that just adds this function and call it on these two lines: |
@ferventcoder please fix this bug
|
Ran a script using chocolatey to install nvm and then use nvm. Tried refreshenv in script. I am running the script in windows powershell. I know I have two workarounds.
But it is crazy how long this issue has sat unfixed. We need a working refreshenv that actually reloads the environment as if we had just started powershell at the point of running refreshenv. |
Diagnostic for are you running the chocolatey version Get-Command refreshenv and in cmd where refreshenv choco upgrade nvm -y
nvm install lts
get-command refreshenv
refreshenv
nvm install lts So this probably explains the problem. So the fix would be to make sure the chocolatey profile was imported correctly so that the alias runs and not refreshenv.cmd I fixed typo and confirmed adding $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
} solves the problem. |
What You Are Seeing?
refreshenv
AKA Update-SessionEnvironment does not refresh environment variables which reference an environmental variable which has changed e.g. If $env:Path has just had %NV_HOME% added (as happens after installing NVM) then runningrefreshenv
won't actually make the path variable workWhat is Expected?
To expand references to other variables recursively
How Did You Get This To Happen? (Steps to Reproduce)
I added chocolatey to my PowerShell profile using
Then set up this test case:
I expect to be able to refresh the environment sufficiently such that I can use
$env:thirdReference
in the same session and it'll returnsuccessfully expanded
Output Logs
Solution
Before you assign things like $env:path in Update-SessionEnvironment just call
ExpandEnvironmentVariablesRecursive
on the value first.I've also added this as a stackoverflow answer
The text was updated successfully, but these errors were encountered: