1

I a tool just downloaded that opens a Visual Studio Command prompt from within the IDE, in the root of the current project. My main gripe is that it opens an old style command window, where I would rather have a PowerShell window. According to this post, this simple change should allow this:

cmd.exe /k ""%VS120COMNTOOLS%VsDevCmd.bat" & powershell"

When I this command from outside of VS 2015, it seems to work fine and gives me a PowerShell window. Yet when I try and run it from inside VS, using the utility's menu item, it gives me this error:

Cannot load PSReadline module. Console is running without PSReadline. . : File C:\Users\brady\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. At line:1 char: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 Restricted

My global execution policy is RemoteSigned, but in the same window that show me the error, when I run a Get-ExecutionPolicy, the returned value is Restricted.

I have tried modifying my command to include the PS switch:

cmd /k ""%VS140COMNTOOLS%VsDevCmd.bat" & powershell -ExecutionPolicy Bypass" 

But this still gives me exactly the same error.

The output of the command suggested by @PetSerAl in the comments

[Environment]::Is64BitOperatingSystem;[Environment]::Is64BitProcess;Get-Executi‌​onPolicy -List

gives two different results. The first in a normal PS window external to VS:

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned

And the second in the only PS window I can find inside VS, the Package Manager:

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process    RemoteSigned
  CurrentUser       Undefined
 LocalMachine       Undefined
ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 3
    Show output of this command: `[Environment]::Is64BitOperatingSystem;[Environment]::Is64BitProcess;Get-ExecutionPolicy -List`. – user4003407 Jan 05 '16 at 10:08
  • As an aside, you may want to look at using [StudioShell](https://studioshell.codeplex.com/) for your Powershell needs within Visual Studio. – rrirower Jan 05 '16 at 13:28
  • @PetSerAl I'll check that out when get back to work on that project, but thank you very much for the tip on StudioShell. Installing as I type. – ProfK Jan 05 '16 at 14:42
  • You could try `powershell -noprofile`. – rojo Jan 07 '16 at 14:57
  • @PetSerAl I have updated the OP with the results from your command. – ProfK Jan 07 '16 at 19:14
  • You missing `[Environment]::Is64BitOperatingSystem;[Environment]::Is64BitProcess` part of my comment. It is essential because `LocalMachine` scope separate for 32-bit and 64-bit processes. And I wanted to see output of that command for windows where `Get-ExecutionPolicy` return `Restricted`, so to know from which scope that `Restricted` come. – user4003407 Jan 08 '16 at 06:50
  • @PetSerAl I don't know how you are reading, but I copied and pasted your command directly into my question. To me, it looks the same there, in your first comment, and the same as your comment here. IT does show all the execution policies, just none are 'restricted'. – ProfK Jan 08 '16 at 10:26
  • @ProfK But where in your question two boolean values what returned by `[Environment]::Is64BitOperatingSystem;[Environment]::Is64BitProcess` part of my command? I see only results of `Get-Executi‌​onPolicy -List`. – user4003407 Jan 08 '16 at 10:55
  • @PetSerAl Oh, I see them, but I edited them out to post the list results. They are both `True` outside VS, and the 2nd one `False` in VS, as VS has always been and still is a 32bit process. – ProfK Jan 08 '16 at 12:56

1 Answers1

1

You can configure an external command and optionally configure a keystroke for it.

I just did this in my VS2015...neat!

Create a cmd file

Create cmd file to call VsDevCmd.bat (Developer Command Prompt for VS2015) and then PowerShell.

dev14powershell.cmd

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
powershell -ExecutionPolicy Bypass

Configure External Tool

Tools -> External Tools

VS2015 External Tools

Calls the cmd file above, starts in Solution Dir (configurable)

Run the new External Tool

Run PowerShell External Tool

Result

A new command window started in Solution Directory.

Optional, configure keyboard shortcut

Tools -> Options -> Keyboard

Search for external and remember the number/order of the command you created (4 in my case)

Command shortcut key

Hit assign and you have:

Powershell Shortcut

Kory Gill
  • 6,993
  • 1
  • 25
  • 33