Skip to content

Instantly share code, notes, and snippets.

@LSTANCZYK
Forked from haacked/FormatAllFiles.ps1
Last active August 29, 2015 14:09
Show Gist options
  • Save LSTANCZYK/7db6cd20fa4e250db446 to your computer and use it in GitHub Desktop.
Save LSTANCZYK/7db6cd20fa4e250db446 to your computer and use it in GitHub Desktop.
// Open up the NuGet Package Manager in Visual Studio and paste the following line to format every file in the solution.
// I'll write a not-so-ugly version later. ;)
// BUG! This doesn't recursively grab all files from the project. :(
$dte.Solution.Projects | ForEach-Object {$_.ProjectItems | ForEach-Object { if ($_.Name.EndsWith('.cs')) {$window = $_.Open('{7651A701-06E5-11D1-8EBD-00A0C90F26EA}'); if ($window){Write-Host $_.Name;[System.Threading.Thread]::Sleep(100);$window.Activate();$_.Document.DTE.ExecuteCommand('Edit.FormatDocument');$_.Document.DTE.ExecuteCommand('Edit.RemoveAndSort');$window.Close(1);}} }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment