Package Manager Console Does not Have Access to Global Variables

Publish date: Jul 5, 2018
Tags: powershell, windows, visual studio

The problem

So you get this message:

The term … is not recognized ...

from Package Manager Console. Even though that same command works in Powershell.

It gets annoying when, after getting used to Package Manager Console in Visual Studio to quickly install/remove Nuget packages, you realize that it can`t run most of other commands, because it doesnt recognize your system and user Environment Variables (not that it’s supposed to :-) ).

The solution

Luckily there is way to remedy this situation. Actually, there are 3:

  1. Run Visual Studio as Administrator. This one is quick, but I don`t think VS is supposed to run with Admin privileges all the time.

  2. Just use the Package Manager Console for packages and have your Powershell opened as separate window. This has 2 drawbacks. You will often have to manually go to solution directory in Powershell to do sth. And you have no way to use keyboard shortcut to quickly jump to Powershell.

  3. My favorite. In VS go to:

    • Tools | Extensions | Online | Type this in search bar: Open Command Line
    • Download it
    • Restart VS and wait for installation to finish
    • (Optional) In VS press Ctrl+q and type in: ‘keyboard’, then:
      • Go to keyboard settings
      • In text box labeled ‘Show commands containing’ type: ‘powershell’.
      • Click on: ‘DebuggerContextMenus…OpenCommandLine.PowerShell’
      • At the bottom assign it a key/key combination you want to use to launch it. It is Shift+Alt+. by default. I prefer Alt+P, you might prefer something else completely.

Now the nice thing is, not only can you open Powershell from VS with your favorite key combination, you have access to those variables as well. And to top it off, notice that the path in Powershell is automatically your solution directory path, which is really nice. Enjoy your coding and stay productive!