Create a gist now

Instantly share code, notes, and snippets.

Embed
Format all CS files in a Visual Studio solution (UGLY VERSION)
// 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);}} }}
@TravisTheTechie

This comment has been minimized.

Show comment
Hide comment
@TravisTheTechie

TravisTheTechie May 21, 2011

http://nuget.codeplex.com/workitem/1055 does it recursively. Well, not the same action, but takes an action.

http://nuget.codeplex.com/workitem/1055 does it recursively. Well, not the same action, but takes an action.

@brianschmitt

This comment has been minimized.

Show comment
Hide comment
@brianschmitt

brianschmitt May 21, 2011

Looks like you have been after a solution to this problem for awhile now - back in 2009 I blogged about a Tweet you made and provided a macro solution to achieve this:
http://www.brianschmitt.com/2009/09/quickly-reformat-your-project-files.html

I know its not nuget, but it is a solution, and it works recursively. ;)

Looks like you have been after a solution to this problem for awhile now - back in 2009 I blogged about a Tweet you made and provided a macro solution to achieve this:
http://www.brianschmitt.com/2009/09/quickly-reformat-your-project-files.html

I know its not nuget, but it is a solution, and it works recursively. ;)

@Haacked

This comment has been minimized.

Show comment
Hide comment
@Haacked

Haacked May 22, 2011

Owner

Haacked commented May 22, 2011

@keyvan

This comment has been minimized.

Show comment
Hide comment
@keyvan

keyvan May 23, 2011

I had also written a blog post on this in 2008:

http://www.nayyeri.net/simpler-code-addin-for-visual-studio-2008

keyvan commented May 23, 2011

I had also written a blog post on this in 2008:

http://www.nayyeri.net/simpler-code-addin-for-visual-studio-2008

@bsimser

This comment has been minimized.

Show comment
Hide comment
@bsimser

bsimser May 24, 2011

It looks like you're trying to write PowerShell. Would you like me to launch the PowerShell for Dummies Clippy Lives Forever Edition for you to do this?

bsimser commented May 24, 2011

It looks like you're trying to write PowerShell. Would you like me to launch the PowerShell for Dummies Clippy Lives Forever Edition for you to do this?

@kiquenet

This comment has been minimized.

Show comment
Hide comment
@kiquenet

kiquenet Nov 27, 2014

Not ugly version for VS 2012 and VS 2013 ?

Not ugly version for VS 2012 and VS 2013 ?

@ahmadalli

This comment has been minimized.

Show comment
Hide comment
@ahmadalli

ahmadalli Aug 27, 2016

it's great but it has a little problem: it doesn't walk through projects in folders

it's great but it has a little problem: it doesn't walk through projects in folders

@ahmadalli

This comment has been minimized.

Show comment
Hide comment
@ahmadalli

ahmadalli Aug 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment