【发布时间】:2016-01-08 16:02:19
【问题描述】:
我刚刚下载了一个工具,它在 IDE 中打开了一个 Visual Studio 命令提示符,位于当前项目的根目录中。我的主要抱怨是它打开了一个旧式命令窗口,我宁愿在其中有一个 PowerShell 窗口。根据this post,这个简单的更改应该允许:
cmd.exe /k ""%VS120COMNTOOLS%VsDevCmd.bat" & powershell"
当我从 VS 2015 外部执行此命令时,它似乎工作正常并给了我一个 PowerShell 窗口。然而,当我尝试从 VS 内部使用实用程序的菜单项运行它时,它给了我这个错误:
无法加载 PSReadline 模块。控制台在没有 PSReadline 的情况下运行。 . : 文件 C:\Users\brady\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 无法加载,因为在此系统上禁用了正在运行的脚本。 有关详细信息,请参阅 about_Execution_Policies,网址为 http://go.microsoft.com/fwlink/?LinkID=135170。在行:1 字符:3 + . 'C:\Users\brady\Documents\WindowsPowerShell\Microsoft.PowerShell_pr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess PS C:\Development\vNext\Commerce\src\Commerce.Test> Get-Execution-Policy PS C:\Development\vNext\Commerce\src\Commerce.Test> Get-ExecutionPolicy 受限
我的全局执行策略是RemoteSigned,但在显示错误的同一窗口中,当我运行Get-ExecutionPolicy 时,返回值是Restricted。
我已尝试修改我的命令以包含 PS 开关:
cmd /k ""%VS140COMNTOOLS%VsDevCmd.bat" & powershell -ExecutionPolicy Bypass"
但这仍然给了我完全相同的错误。
@PetSerAl 在 cmets 中建议的命令的输出
[Environment]::Is64BitOperatingSystem;[Environment]::Is64BitProcess;Get-ExecutionPolicy -List
给出两种不同的结果。第一个在 VS 外部的普通 PS 窗口中:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
我可以在 VS 中找到的唯一 PS 窗口中的第二个,包管理器:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process RemoteSigned
CurrentUser Undefined
LocalMachine Undefined
【问题讨论】:
-
显示此命令的输出:
[Environment]::Is64BitOperatingSystem;[Environment]::Is64BitProcess;Get-ExecutionPolicy -List. -
顺便说一句,您可能想看看在 Visual Studio 中使用 StudioShell 来满足您的 Powershell 需求。
-
@PetSerAl 我会在重新开始该项目时检查一下,但非常感谢您提供有关 StudioShell 的提示。在我输入时安装。
-
你可以试试
powershell -noprofile。 -
@PetSerAl 我已经用你的命令的结果更新了 OP。
标签: powershell batch-file visual-studio-2015 executionpolicy