Мне нужно добавить дополнительную папку в переменную среды PATH, когда я запускаю PowerShell из кода VisualStudio. Это изменение должно существовать только при запуске PowerShell из VisualStudio, так как я не хочу, чтобы эти дополнительные утилиты были доступны иначе (т. Е. Обновление переменной PATH в настройках Windows невозможно).
Я предпринял несколько попыток изменить настройки пользователя, но ни одна из них, похоже, не работает.
Попытка 1
"terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows" : [
"-NoExit",
"-Command \"& {$Env:Path += ';C:\\tools'}\""
]
Результат: PowerShell запускается со следующей ошибкой.
-Command : The term '-Command' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
+ -Command "& {$Env:Path += 'C:\tools'}"
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-Command:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Попытка 2
"terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows" : [
"-NoExit",
"-Command",
"\"& {$Env:Path += 'C:\\tools'}\""
]
Результат: PowerShell запускается со следующим выводом, но каталог «C: \ tools» не добавляется к переменной env PATH.
& {C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;... += 'C:\tools'}
Кто-нибудь знает, как вызвать PowerShell с расширенной переменной PATH из кода VisualStudio?