使用dotnet-format更改为c#10中的文件划分的名称空间
我想将文件格式化为“文件划分的名称空间”。我只想做出改变。
我的.editorConfig
仅包含以下内容:
[*.cs]
csharp_style_namespace_declarations = file_scoped:warning # config for IDE0161
测试文件foo.cs
:
namespace MyNamespace
{
public class Foo
{
public Foo(int someInt, string someString)
{
_someInt = someInt; // aligned
_someString = someString; // aligned
}
private readonly int _someInt;
private readonly string _someString;
}
}
我运行此:
dotnet format MyProject.csproj --severity info --diagnostics=IDE0161 --include=Foo.cs
结果:
namespace MyNamespace;
public class Foo
{
public Foo(int someInt, string someString)
{
_someInt = someInt; // not aligned
_someString = someString; // not aligned
}
private readonly int _someInt;
private readonly string _someString;
}
如图所示,对齐方式更改。还有其他各个地方也改变了对齐方式。
我只想运行一个分析仪/修复程序 - iDE0161
。我不希望格式命令做其他任何事情。
我该怎么做?
(请注意,如果我在VSCODE中运行代码修复,则可以使用。它仅通过dotnet格式
失败。)
I want to format a file to "file-scoped namespaces". I want to make that change only.
My .editorconfig
contains this only:
[*.cs]
csharp_style_namespace_declarations = file_scoped:warning # config for IDE0161
A test file Foo.cs
:
namespace MyNamespace
{
public class Foo
{
public Foo(int someInt, string someString)
{
_someInt = someInt; // aligned
_someString = someString; // aligned
}
private readonly int _someInt;
private readonly string _someString;
}
}
I run this:
dotnet format MyProject.csproj --severity info --diagnostics=IDE0161 --include=Foo.cs
The result:
namespace MyNamespace;
public class Foo
{
public Foo(int someInt, string someString)
{
_someInt = someInt; // not aligned
_someString = someString; // not aligned
}
private readonly int _someInt;
private readonly string _someString;
}
The alignment is changed as shown. There are various other places where alignment is changed too.
I only want to run one analyser/fixer - IDE0161
. I don't want the format command to do anything else.
How do I do that?
(Note if I run the code fix in vscode, it works. It's only via dotnet format
that it fails.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论