Skip to content

Instantly share code, notes, and snippets.

@ccbristo
Created April 5, 2013 17:57
Show Gist options
  • Save ccbristo/5321301 to your computer and use it in GitHub Desktop.
Save ccbristo/5321301 to your computer and use it in GitHub Desktop.
A few VS macros to open powershell.
Option Infer On
Option Compare Text
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.IO
Public Module OpenInPowerShellModule
Public Sub OpenPowerShellHere_Solution()
Dim directory = Path.GetDirectoryName(DTE.Solution.FullName)
OpenPowerShell(directory)
End Sub
Public Sub OpenPowerShellHere_Project()
Dim activeProject = GetActiveProject()
Dim directory = Path.GetDirectoryName(activeProject.FileName)
OpenPowerShell(directory)
End Sub
Public Sub OpenPowerShellHere_ProjectItem()
Dim x As UIHierarchyItem = DTE.ToolWindows.SolutionExplorer.SelectedItems(0)
Dim item As ProjectItem = x.Object
Dim directory = Path.GetDirectoryName(item.FileNames(0))
OpenPowerShell(directory)
End Sub
Private Sub OpenPowerShell(ByVal directory As String)
Dim p = New System.Diagnostics.Process()
p.StartInfo = New ProcessStartInfo("C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe")
p.StartInfo.UseShellExecute = True
p.StartInfo.Arguments = "-PSConsoleFile ""C:\Program Files (x86)\Microsoft Team Foundation Server 2008 Power Tools\tfshell.psc1"" " & _
"-noexit " & _
"-command "". 'C:\Program Files (x86)\Microsoft Team Foundation Server 2008 Power Tools\TFSSnapin.ps1'"""
p.StartInfo.WorkingDirectory = directory
p.Start()
End Sub
Private Function GetActiveProject() As Project
Dim activeProject As Project = Nothing
Dim activeProjects() As Object = DTE.ActiveSolutionProjects
If activeProjects IsNot Nothing AndAlso activeProjects.Length > 0 Then
activeProject = CType(activeProjects.GetValue(0), Project)
End If
Return activeProject
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment