dotnet全局锁_使用.NET Core的dotnet格式全局工具从命令行设置EditorConfig代码格式

dotnet全局锁

dotnet全局锁

"EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs." Rather than you having to keep your code in whatever format the team has agreed on, you can check in an .editorconfig file and your editor of choice will keep things in line.

EditorConfig有助于维护跨各种编辑器和IDE从事同一项目的多个开发人员的一致编码风格。” 您不必签入团队同意的任何格式的代码,而可以签入.editorconfig文件,您选择的编辑器将使一切保持一致。

If you're a .NET developer like myself, there's a ton of great .NET EditorConfig options you can set to ensure the team uses consistent Language Conventions, Naming Conventions, and Formatting Rules.

如果您是像我这样的.NET开发人员,则可以设置大量的.NET EditorConfig选项,以确保团队使用一致的语言约定,命名约定和格式设置规则。

  • Language Conventions are rules pertaining to the C# or Visual Basic language, for example, var/explicit type, use expression-bodied member.

    语言约定是与C#或Visual Basic语言相关的规则,例如var / explicit类型,使用表达式主体成员。

  • Formatting Rules are rules regarding the layout and structure of your code in order to make it easier to read, for example, Allman braces, spaces in control blocks.

    格式规则是与代码的布局和结构有关的规则,以便于阅读,例如Allman大括号,控制块中的空格。

  • Naming Conventions are rules respecting the way objects are named, for example, async methods must end in "Async".

    命名约定是关于对象命名方式的规则,例如, async方法必须以“异步”结尾。

If you're using Visual Studios 2010, 2012, 2013, or 2015, fear not. There's at least a basic EditorConfig free extension for you that enforces the basic rules. There is also an extension for Visual Studio Code to support EditorConfig files that takes just seconds to install.

如果您使用的是Visual Studios 2010、2012、2013或2015,请不要担心。 至少有一个基本的EditorConfig free扩展可以为您实施基本规则。 Visual Studio Code还有一个扩展来支持EditorConfig文件,该文件只需几秒钟即可安装

ASIDE: If you are looking for a decent default for C#, take a look at the .editorconfig that the C# Roslyn compiler team uses. I don't know about you, but my brain exploded when I saw that they used spaces vs tabs.

旁白:如果您正在寻找C#的不错的默认值,请查看C#Roslyn编译器团队使用的.editorconfig 。 我不认识你,但是当我看到他们使用空格和制表符时,我的大脑爆炸了。

But! What if you want this coding formatting goodness at the dotnet command line? You can use "dotnet format" as a global tool! It's one line to install, then it's available everywhere for all your .NET Core apps.

但! 如果您希望在dotnet命令行中具有这种编码格式优势,该怎么办? 您可以将“ dotnet格式”用作全局工具! 这是一条安装线,然后可在所有.NET Core应用程序中随处使用。

D:\github\hanselminutes-core> dotnet tool install -g dotnet-format
You can invoke the tool using the following command: dotnet-format
Tool 'dotnet-format' (version '3.0.2') was successfully installed.
D:\github\hanselminutes-core> dotnet format
Formatting code files in workspace 'D:\github\hanselminutes-core\hanselminutes-core.sln'.
Found project reference without a matching metadata reference: D:\github\hanselminutes-core\hanselminutes.core\hanselminutes-core.csproj
Formatting code files in project 'hanselminutes-core'.
Formatting code files in project 'hanselminutes.core.tests'.
Format complete.

You can see in the screenshot below where dotnet format used its scandalous defaults to move my end of line { to its own line! Well, if that's what the team wants! ;)

您可以在下面的屏幕截图中看到,dotnet格式使用了其丑陋的默认设置将我的行尾{移至其自己的行! 好吧,如果这就是团队想要的! ;)

My code is automatically formatted by the dotnet format tool

Of course, dotnet format is all open source and up at https://github.com/dotnet/format. You can install the stable build OR a development build from myGet.

当然,dotnet格式都是开源的,并且可以在https://github.com/dotnet/format上找到。 您可以从myGet安装稳定版本开发版本

翻译自: https://www.hanselman.com/blog/editorconfig-code-formatting-from-the-command-line-with-net-cores-dotnet-format-global-tool

dotnet全局锁

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值