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.
Examples
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