it:ad:powershell:howto:automate_visual_studio

IT:AD:Powershell:HowTo:Automate Visual Studio

Summary

Once you've figured out how to run Powershell scripts within Visual Studio (Run scripts within the Package Manager Console) it opens up all kinds of possibilities.

PS> # Example 1: Open *.cs files under current dir tree in VS
PS>
PS> Get-ChildItem . -Recurse -Include *.cs | %{ $dte.ItemOperations.OpenFile($_) }
 
 
PS> # Example 2: Invoke NewProject dialog
PS> $dte.ExecuteCommand("File.NewProject")
 
 
PS> # Example 3: Add 10 class files to current project (with a C#/VB project active)
PS> 1..10 | %{ $dte.ItemOperations.AddNewItem("Code\Class") }
 
 
PS> # Example 4: Close all opened document windows
PS> $dte.Documents | %{ $_.Close() }

Get Path to current solution

$dte.solution.FullName

Get Active Project

# seems to always return an array of 1, of the current active project.
$dte.ActiveSolutionProjects

Get Active File

$dte.ActiveDocument.Name

  • /home/skysigal/public_html/data/pages/it/ad/powershell/howto/automate_visual_studio.txt
  • Last modified: 2023/11/04 23:01
  • by 127.0.0.1