当我从PowerShell代码运行VisualStudio时,我需要在PATH环境变量中附加一个额外的文件夹。只有在从PowerShell内部运行VisualStudio时,此更改才会存在,因为我不希望这些额外的实用程序以其他方式可用(例如,更新VisualStudio设置中的路径变量不是一个选项)。
我做了几次尝试修改我的用户设置,但似乎都没有效果。
尝试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“dir没有附加到PATH env变量。
& {C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;... += 'C:\tools'}有人知道如何使用扩展的路径变量从PowerShell代码中调用VisualStudio吗?
发布于 2019-01-14 21:07:14
我对VSCode并不特别熟悉,但是根据错误,尝试1似乎是非常接近的。我认为以下几点是可行的:
"terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"terminal.integrated.shellArgs.windows" : [
"-NoExit",
"$Env:Path += ';C:\\tools'"
]https://stackoverflow.com/questions/54188898
复制相似问题