Visual Studio,每个解决方案缩进设置
我正在处理一些不同的事情,有些使用制表符,有些使用 2 个空格进行缩进,另一些用户使用 4 个空格进行缩进等。
在 Visual Studio 中设置此选项的选项位于“工具”->“选项”->“文本编辑器”中-><语言>->选项卡
是否有某种方法可以在每个解决方案的基础上覆盖这些设置?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
更新:VS 2017 原生支持 EditorConfig: https://blogs.msdn.microsoft.com/dotnet/2016/12/15/code-style-configuration-in-the-vs2017-rc-update/
在 VS 2010 和上面,有一个扩展根据解决方案/项目根目录中的 .editorconfig 文件设置缩进:
http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328< /a>
还有类似的 Visual Studio Code 扩展。
UPDATE: VS 2017 supports EditorConfig natively: https://blogs.msdn.microsoft.com/dotnet/2016/12/15/code-style-configuration-in-the-vs2017-rc-update/
In VS 2010 and above, there's an extension that sets the indentation based on .editorconfig file in the solution/project root:
http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328
There's also similar extension for Visual Studio Code.
这是实现您正在寻找的目标的一种(诚然是黑客)方法:
1)创建一个更改缩进的宏(source)
2) 将其与您的解决方案加载挂钩:
在宏资源管理器中,选择
EnvironmentEvents
,在第一个下拉列表中选择SolutionEvents
,在第二个下拉列表中选择Opened
。现在,您有了一个每次打开解决方案时都会触发的宏。
您只需将解决方案映射到所需的缩进即可。
Here is one (admittedly hacky) way to achieve what you are looking for:
1) create a macro that changes the indentation (source)
2) Hook that up with your solution loading:
In the macro explorer, choose
EnvironmentEvents
, selectSolutionEvents
in the first drop-down,Opened
in the second.You now have a macro that will trigger every time you open a solution.
You just need to map your solutions to the required indentation.
现在还有另一个名为“Rebracer”的加载项...链接位于:http://visualstudiogallery.msdn.microsoft.com/410e9b9f-65f3-4495-b68e-15567e543c58
There's also another Add-in called "Rebracer" now... link is here: http://visualstudiogallery.msdn.microsoft.com/410e9b9f-65f3-4495-b68e-15567e543c58
从 VS 扩展 EditorConfig (http://visualstudiogallery.msdn.microsoft.com /c8bccfe2-650c-4b42-bc5c-845e21f96328)网站:
(强调我的)
全面披露:我无法亲自测试它(因为 ReSharper 接管)。
From the VS extension EditorConfig (http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328) website:
(emphasis mine)
Full Disclosure: I have not been able to personally test it (because ReSharper takes over).
VS2017 RC 添加了对 .editorconfig 格式的支持。
VS2017 RC added support for .editorconfig format.
您可以使用
props.Item("InsertTabs") = bool
设置插入制表符/空格设置,请查看:https://github.com/jamesfoster/VS-Whitespace-Macros
You can set the Insert Tabs/Spaces setting with
props.Item("InsertTabs") = bool
Check this out: https://github.com/jamesfoster/VS-Whitespace-Macros
更新:似乎缩进不是由Resharper管理的,所以这个答案实际上并没有解决具体问题。 然而,它确实适用于一般术语; 即“Visual Studio,每个解决方案设置”,以防有人在这里偶然发现它。
如果您使用 Resharper,您可以保存格式设置(实际上是任何设置)以获取解决方案。 您可以进一步指定是否只适合您(即不致力于源代码控制)或共享特定于解决方案的设置(即提交源代码控制)。
然后在窗口底部的
保存到
下选择“解决方案 XYZ 个人”(或共享,具体取决于您的目的)。这将创建一个 xml 文件
YOURSOLUTION.sln.DotSettings.user
,其值如下:UPDATE: seems like indentation is not managed by Resharper, so this answer does not actually address the specific question. However, it does apply in general terms; i.e. "Visual Studio, per solution settings" in case anyone stumbles here looking for that.
If you are using Resharper, you can save formatting settings (really, any settings) for just the solution. You can further specify if just for you (i.e. not committed to source-control) or shared solution-specific settings (i.e. commit to source-control).
Then at the bottom of the window, under
Save To
choose "Solution XYZ personal" (or shared, depending on your purpose).This creates an xml file
YOURSOLUTION.sln.DotSettings.user
with values like:因此,公认的解决方案说“您只需将解决方案映射到所需的缩进”,这很好,但您如何做到这一点呢? 在浪费了大量时间试图弄清楚之后,我找到了一种我更喜欢的方法 这里。 此方法加载任意数量的导出设置,这些设置对于每个解决方案可能有所不同。 设置可以包括任何内容,从缩进到颜色甚至窗口布局(我认为)。
自动添加处理 SolutionEvents.Opened 事件的代码。 将该代码更改为以下内容:
保存宏。
如果宏未运行,可能是由于 MS 安全补丁的原因。 基于 this,添加以下字符串:
在 下面 标记以下三个文件:
请确保以管理员权限启动用于编辑这些文件的编辑器(即右键单击“记事本”并选择“以管理员身份运行”)。
我还发现 一个插件,它应该执行与上面建议的宏相同的操作,但由于某种原因,在我运行其安装程序后它没有执行任何操作。
So, the accepted solution says "You just need to map your solutions to the required indentation", which is great, except how do you do that? After wasting a lot of time trying to figure that out, I found a method I prefer here. This method loads any number of exported settings that can be different for every solution. Settings can include anything, from indents to colors or even window layout (I think).
Code to handle the SolutionEvents.Opened event is automatically added. Change that code to the following:
Save the macro.
If the macro doesn't run, it could be because of a MS security patch. Based on this, add the following string:
Below the <runtime> tag in the following three files:
Be sure to start the editor you use to edit those files with Administrator privileges (ie right click Notepad and choose 'Run as Administrator').
I also found a plug-in that's supposed to do the same thing as the macro suggested above but for some reason it didn't do anything after I ran its installer.
clang-format 提供了相当复杂的选项来格式化源代码。
Visual Studio 插件非常初级,即它不会自动运行,但它可以很好地完成其工作(即手动调用时)。
http://llvm.org/builds/
clang-format provides quite sophisticated options for formatting your source code.
The Visual Studio plugin is quite rudimentary, i.e. it does not run automatically, but it does its job well (when manually invoked, that is).
http://llvm.org/builds/