Piy*_*ush 2 shell powershell visual-studio-code
如何在 Visual Studio Code 中将 Powershell 脚本作为 noprofile 启动,我可以使用命令PowerShell_Ise -NoProfile运行带有 noprofile 的 Powershell Ise 。但是我们如何在 Visual Studio Code 中为 poershell 会话做同样的事情。
如果您在PowerShell 集成控制台中运行 PowerShell,它是PowerShell 扩展附带的特殊shell :
要关闭此特殊 shell 中的配置文件加载,请确保未选中
PowerShell: Enable Profile LoadingPowerShell 扩展选项(通过, )。File > Preferences > SettingsCtrl-,
有关如何控制在 PowerShell 集成控制台中使用的特定 PowerShell 版本/可执行文件,请参阅底部部分。
如果您在 Visual Studio Code 的集成终端中将PowerShell 作为通用 shell运行:
您必须修改默认的 PowerShell shell 配置文件或添加自定义配置文件,"args"参数值为[ "-noprofile" ],通过直接编辑设置底层的 JSON 文件settings.json(>Preferences: Open Settings (JSON)来自命令面板)。
下面显示了一个相关settings.json摘录,其中包含一个修改过的默认 PowerShell 配置文件,该配置文件抑制了配置文件加载。
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [ "-noprofile" ] // suppress profile loading
}, // ...
}
Run Code Online (Sandbox Code Playgroud)
继续阅读,了解有关 Visual Studio Code 中 shell 和终端的详细一般信息。
3 种不同类型的外壳本质上适用:
集成终端的默认外壳(TERMINAL面板的选项卡)。
tasks.json)而不是默认的集成终端外壳。用于打开外部终端的默认外壳( > Open New External Terminal);请注意,在 Windows 上,您可以直接指定 shell 可执行文件,但在类 Unix 平台上,您必须指定一个终端应用程序,然后它本身决定要启动的 shell - 请参阅下面的详细信息。
安装了PowerShell 扩展后,另一个外壳适用:
这些贝壳:
都可以单独配置
它们的默认行为可能有所不同
只有其中一些允许您指定启动参数,例如-NoProfile在您的情况下。
在默认的外壳是:
SHELL环境变量中。conhost.exe:,启动cmd.exe(命令提示符)Terminal.app在 macOS 上,它本身决定要启动的 shell(尽管默认情况下,它也是用户的默认 shell)。bash.exe),在这种情况下,它会在常规控制台窗口中打开(conhost.exe)以下文件摘录Settings.json( > Preferences: Open Settings (JSON)) 显示了每个文件的相关设置(自 VSCode v1.60 / PowerShell Extension v2021.8.2 起):
"terminal.integrated.shell.*"和"terminal.integrated.shellArgs.*"设置确定了集成终端的默认 shell 及其启动参数。这些已被shell配置文件取代,通过"terminal.integrated.profiles.*"属性定义,以及"terminal.integrated.defaultProfile.*"包含默认使用的配置文件名称的关联属性,如下所示。从 v1.60 开始,这些已弃用的设置现已过时并已停止工作。"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [ "-noprofile" ] // suppress profile loading
}, // ...
}
Run Code Online (Sandbox Code Playgroud)
如果要将 PowerShell 集成控制台配置为使用不同的 PowerShell 版本/版本:
GUI 方法:Terminal在 VSCode 面板(屏幕下半部分)的选项卡中激活 PowerShell 集成控制台,单击右下角的版本号图标(例如,
)
Switch to:Settings.json文件添加其可执行路径(请参阅下一点)。通过settings.json( > Preferences: Open Settings (JSON)):
数组值powershell.powerShellAdditionalExePaths属性允许您添加扩展无法自动找到的 PowerShell 版本的完整可执行路径 - 请参见下面的示例。
该powershell.powerShellDefaultVersion属性确定默认使用哪个版本;由于您必须通过其显示名称指定它,其中包括自动选择的自动发现版本的显示名称,因此通过 GUI 进行选择是最简单的,如上所示。
{
// ...
// **General-purpose integrated-terminal shell**.
// Shell *profiles* define the *available* shells for the integrated terminal.
// This property is situationally created automatically, platform-appropriately,
// based on what shells VSCode finds in standard locations on your
// system.
// However, it *need not be present* in a given file - VSCode
// knows about about *standard* profiles *implicitly* when it
// comes to choosing a default shell.
// This example applies to Windows, and shows that Git Bash
// was found on the system.
// On Unix-like platforms, replace ".windows" with ".osx" or ".linux",
// as appropriate.
// To add custom profiles:
// * In file *paths*, use "\\" or "/" as the path separator.
// * Use an "args" array property to specify start-up arguments, if necessary.
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
// Define the *default* shell profile, which serves as the default
// shell in the *integrated terminal* and - except
// if overridden, as shown below - also for *tasks*.
"terminal.integrated.defaultProfile.windows": "PowerShell"
// **Automation-tasks shell**,
// for the tasks defined in "tasks.json" and for debugging:
// This definition is *optional* and *overrides* the default shell configured above.
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// that is, this setting doesn't reference the shell *profiles*.
// * There is NO way to pass startup arguments.
"terminal.integrated.automationShell.windows": "cmd.exe",
// **External-terminal executable**:
// The *terminal program* to use for opening an external terminal window, which itself determines what shell to launch.
// (> Open New External Terminal).
// Note:
// * The *executable file path* must be specified (just the file name is sufficient for executables present in %PATH%);
// * There is NO way to pass startup arguments.
// * This example specifies Windows Terminal (wt.exe).
// * On Windows only, you may also specify a *shell* executable directly,
// which then opens in a regular console window (conhost.exe)
"terminal.external.windowsExec": "wt.exe",
// **PowerShell Integrated Console**:
// Profile loading is *disabled* by default; you can enable it here, but
// note that the PowerShell Integrated Console has its own,
// separate $PROFILE location, which differs from the one in a
// regular console window. If you want to load your regular profile,
// place the following statement in the $PROFILE file of
// the Integrated Console:
// . ($PROFILE -replace '\.VSCode', '.PowerShell')
// (Open the profile file for editing by submitting the following command
// from the Integrated Console:
// code $PROFILE
// )
"powershell.enableProfileLoading": false,
// ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1956 次 |
| 最近记录: |