首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在启动VisualStudio代码中的集成终端时追加路径?

如何在启动VisualStudio代码中的集成终端时追加路径?
EN

Stack Overflow用户
提问于 2019-01-14 20:44:47
回答 1查看 1.4K关注 0票数 0

当我从PowerShell代码运行VisualStudio时,我需要在PATH环境变量中附加一个额外的文件夹。只有在从PowerShell内部运行VisualStudio时,此更改才会存在,因为我不希望这些额外的实用程序以其他方式可用(例如,更新VisualStudio设置中的路径变量不是一个选项)。

我做了几次尝试修改我的用户设置,但似乎都没有效果。

尝试1

代码语言:javascript
运行
复制
    "terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "terminal.integrated.shellArgs.windows" : [
        "-NoExit",
        "-Command \"& {$Env:Path += ';C:\\tools'}\""
    ]

结果: PowerShell从以下错误开始。

代码语言:javascript
运行
复制
-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

代码语言:javascript
运行
复制
    "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变量。

代码语言:javascript
运行
复制
& {C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;... += 'C:\tools'}

有人知道如何使用扩展的路径变量从PowerShell代码中调用VisualStudio吗?

EN

回答 1

Stack Overflow用户

发布于 2019-01-14 21:07:14

我对VSCode并不特别熟悉,但是根据错误,尝试1似乎是非常接近的。我认为以下几点是可行的:

代码语言:javascript
运行
复制
    "terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "terminal.integrated.shellArgs.windows" : [
    "-NoExit",
    "$Env:Path += ';C:\\tools'"
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54188898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档