如何格式化在Visual Studio 2012中的所有文件? [英] How to format all files in Visual Studio 2012?

查看:417
本文介绍了如何格式化在Visual Studio 2012中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与Visual Studio的早期版本,我用凯文·皮尔希,比森的剧本格式在我的解决方案,所有的C#文件。

With previous versions of Visual Studio, I used Kevin Pilch-Bisson's script to format all C# files in my solution.

VS2012下降的宏观支持,所以不能正常工作了。

VS2012 dropped macro support, so that doesn't work any more.

我怎么能轻易格式化我的所有文件在VS2012?

How can I easily format all my documents in VS2012?

推荐答案

打开<大骨节病>工具 - > <大骨节病>库包管理器 - > <大骨节病>软件包管理器控制台,并运行以下命令。最后,所有的文件将在IDE中打开。 (低-RAM的机器将有大的解决方案。)修改过的文件将是
在IDE修改,并且不被保存到磁盘。您可以保存所有,然后关闭所有,如果你准备好了。

Open Tools->Library Package Manager->Package Manager Console, and run the command below. At the end, all documents will be open in the IDE. (Low-RAM machines will have problems with large solutions.) Changed files will be modified in the IDE, and not saved to disk. You can Save All, then Close All if you're ready.

VS2012去掉,在以前的版本
的Visual Studio中存在的VB般的宏语言。然而,底层的DTE接口仍然存在,而你
可以通过PowerShell的实现它,在Package Manager控制台

VS2012 removed the VB-like macro language that existed in previous version of Visual Studio. However, the underlying DTE interface is still there, and you can reach it via PowerShell, in the Package Manager Console

怪异的GUID传递到的 ProjectItem.Open
Constants.vsViewKindCode

The weird GUID passed to ProjectItem.Open is Constants.vsViewKindCode.

一般情况下我这个拆分中多行,但包管理器控制台
不支持续行。

Normally I'd split this in to multiple lines, but the Package Manager Console doesn't support line continuation.

您可以在 https://gist.github.com/JayBazuzi/9e0de544cdfe0c7a4358找到最新版本

function f($projectItems) { $projectItems | ? { $_.Name.EndsWith( ".cs" ) } | % { $win = $_.Open('{7651A701-06E5-11D1-8EBD-00A0C90F26EA}') ; $win.Activate() ; $DTE.ExecuteCommand('Edit.FormatDocument') } ; if ($projectItems) { $projectItems | % { f($_.projectItems) } } }

$dte.Solution.Projects | % { f($_.ProjectItems) }

这篇关于如何格式化在Visual Studio 2012中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆