Sha*_*tin 6 c# resharper stylecop visual-studio
我们希望Reorder using statements,让他们外面的namespace。ReSharpernamespace在重新排序时将它们放在里面。
用于放置 using 指令的 Visual Studio 或 Resharper 功能询问如何放置usings在namespace.这不是我们想要做的。它的答案建议去ReSharper > Options > Code Editing ? C# ? Code Style ? Add 'using' directive to the deepest scope。尽管已取消选择,但在重新usings排序 时,ReSharper 将使用放在namespace.
我们怎样才能Reorder using statements把它们排除在外namespace?
我们尝试过的其他事情:
我们的 StyleCop.Analyzers 规则集包括以下指令相关规则:
SA1200 Using directives must be placed correctly
SA1208 System using directives must be placed before other using directives
SA1209 Using alias directives must be placed after other using directives
SA1210 Using directives must be ordered alphabetically by namespace
Run Code Online (Sandbox Code Playgroud)
鉴于这些规则以及选项中不“添加usings到最深范围”的选择,我们在构建时收到以下警告:
SA1200 Using directive must appear within a namespace declaration.
Run Code Online (Sandbox Code Playgroud)
我们如何配置 ReSharper 以强制 using 指令必须出现在命名空间声明之外?
stylecop.json使用以下设置添加到项目中:
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace"
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后,通过编辑文件启用使用,stylecop.jsonProjectName.csproj在项目文件中找到以下项目...
<None Include="stylecop.json" />
Run Code Online (Sandbox Code Playgroud)
...并将定义更改为以下内容。
<AdditionalFiles Include="stylecop.json" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1630 次 |
| 最近记录: |