如何在Visual Studio代码中以noprofile的身份启动Powershell脚本
如何在Visual Studio代码中以noprofile的形式启动Powershell脚本,我可以使用命令Powershell_Ise-noprofile运行Powershell Ise和noprofile。但是我们如何在Visual Studio代码中对poershell会话执行相同的操作。您可以进入powershell扩展设置并删除“powershell:启用配置文件加载”复选框,我认为这会有所帮助。还要检查任务是否在Visual Studio代码的上下文中运行带有某些参数的powershell脚本:如何在Visual Studio代码中以noprofile的身份启动Powershell脚本,powershell,Powershell,如何在Visual Studio代码中以noprofile的形式启动Powershell脚本,我可以使用命令Powershell_Ise-noprofile运行Powershell Ise和noprofile。但是我们如何在Visual Studio代码中对poershell会话执行相同的操作。您可以进入powershell扩展设置并删除“powershell:启用配置文件加载”复选框,我认为这会有所帮助。还要检查任务是否在Visual Studio代码的上下文中运行带有某些参数的powersh
- 3种不同类型的壳在本质上适用:
- 集成终端的默认外壳(面板的
终端选项卡)
- 可选地,自动化外壳用于自动化任务(在
中定义),而不是默认的集成终端外壳tasks.json
- 可选地,自动化外壳用于自动化任务(在
- 用于打开外部终端的默认外壳(
)>打开新的外部终端
- 集成终端的默认外壳(面板的
- 安装了后,另一个shell适用:
- 要用于PowerShell集成控制台的特定PowerShell可执行文件,它提供了与编辑紧密集成的功能,并支持调试PowerShell代码
- 都可以单独配置
- 它们的默认行为可能有所不同
- 只有其中一些允许您指定启动参数,例如您的案例中的
-NoProfile
Settings.json
文件(>首选项:打开设置(json)
)显示了每个文件的相关设置(从VSCode v1.42/PowerShell Extension 2020.3.0开始):
如果要将PowerShell集成控制台配置为使用不同的PowerShell版本:
- GUI方法:当PowerShell集成控制台在VSCode面板(屏幕下半部分)的
终端
选项卡中处于活动状态时,单击右下角的版本号图标(例如)
- 选择另一个版本(如果存在),前缀为
切换到:
- 如果未显示感兴趣的版本,则必须通过
文件添加其可执行路径(参见下一点)Settings.json
- 选择另一个版本(如果存在),前缀为
- 通过
(settings.json
):>首选项:打开设置(json)
- 数组值
属性允许您添加扩展无法自动找到的powershell版本的完整可执行路径-请参见下面的示例powershell.powerShellAdditionalExePaths
属性确定默认使用哪个版本;由于必须通过其显示名称来指定它,其中包括自动查找版本的自动选择的显示名称,因此最简单的方法是通过GUI进行选择,如上图所示powershell.powerShellDefaultVersion
- 数组值
{
// ...
// **General-purpose integrated-terminal shell**:
// Mere file *names* work for executables that are in %PATH%; e.g., "cmd.exe"
// If you need to specify a file *path*, use "\\" or "/" as the path separator.
// On Unix-like platforms, replace ".windows" with ".osx" or ".linux",
// as appropriate.
"terminal.integrated.shell.windows": "powershell.exe",
// Startup parameters to pass to the specified shell.
// On Unix-like platforms, replace ".windows" with ".osx" or ".linux",
// as appropriate.
"terminal.integrated.shellArgs.windows": "-NoProfile",
// **Automation-tasks shell**,
// for the tasks defined in "tasks.json" and for debugging:
// This overrides the default shell configured above.
// Note: There is NO way to pass startup arguments.
"terminal.integrated.automationShell.windows": "cmd.exe",
// **External-terminal shell**:
// The executable to use for opening an external terminal window
// (> Open New External Terminal).
// Note: There is NO way to pass startup arguments,
// so you cannot suppress profile loading, for instance.
"terminal.external.windowsExec": "powershell.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,
// ...
}
{
// ...
// The paths to any PowerShell executables that the extension cannot auto-discover.
// The "versionName" is a self-chosen name that is offered in the
// version-selector menu that pops up when you click on the version number
// near the right edge of the status bar when the
// PowerShell Integrated Console is active.
// (The currently active version is displayed by its actual characteristics,
// not by its "versionName" property; e.g.,
// "PowerShell 7.0 (X64) Core Edition [7.0.0]")
"powershell.powerShellAdditionalExePaths": [
{
"versionName": "Latest Preview",
"exePath": "C:\\Users\\jdoe\\AppData\\Local\\Microsoft\\powershell\\pwsh.exe"
}
],
// The "versionName" property of the PowerShell executable to use by default.
// Note: To switch to an executable that the extension found automatically,
// it is simplest to use the version-selector menu.
"powershell.powerShellDefaultVersion": "Latest Preview",
// ...
}