“CS8700:多个分析器配置文件不能位于同一目录中”,但只有一个 StyleCop 文件

Met*_*ose 21 c# configuration stylecop build analyzer

我正在尝试学习在个人项目中使用 StyleCop。这不是一个很大的解决方案结构如下:

- MySolution (2 of 2 projects)
   - Solution Items
      - .editorconfig
      - .gitignore
      - CODEOWNERS
      - my-pipeline-workflow.yml
      - README.md
      - stylecop.json
   - MyMainProject
      - Dependencies
      - .editorconfig (pointer Solution Items copy)
      - OneOfManyCsFiles.cs
      - stylecop.json (pointer Solution Items copy)
   - MyTestProject
      - Dependencies
      - .editorconfig (pointer Solution Items copy)
      - OneOfManyTestCsFiles.cs
      - stylecop.json (pointer Solution Items copy)
Run Code Online (Sandbox Code Playgroud)

以下是文件夹本身的结构:

- RepoFolder
   - .github
      - workflows
         - my-pipeline-workflow.yml
   - src
      - MyMainProject.csproj
      - OneOfManyCsFiles.cs
   - test
      - MyTestProject.csproj
      - OneOfManyTestCsFiles.cs
   - .editorconfig
   - .gitignore
   - CODEOWNERS
   - MySolution.sln
   - README.md
   - stylecop.json
Run Code Online (Sandbox Code Playgroud)

在为 StyleCop 添加文件之前一切正常。我可以在 Visual Studio 中很好地构建和测试。无论出于何种原因,添加 StyleCop 文件(也可能是该.editorconfig文件)似乎在构建时导致了此错误:

CSC: error CS8700: Multiple analyzer config files cannot be in the same directory ('/home/runner/work/MySolution/MySolution').
[/home/runner/work/MySolution/MySolution/src/MyMainProject.csproj]
Run Code Online (Sandbox Code Playgroud)

据我了解,StyleCop 文件是唯一的分析器文件,并且在多个地方引用了它。是否.editorconfig以某种方式算作另一个分析器文件?如果是这样,我该如何让他们玩得愉快?

抑制错误.editorconfig没有任何作用。当我单独搜索错误时也找不到任何有用的文档。

jei*_*iea 18

仅供其他谷歌用户参考。

我使用NiccoMlt的结构,但遇到了CS8700。我通过从有问题的项目文件中删除以下内容解决了这个问题。

  <ItemGroup>
    <EditorConfigFiles Include=".editorconfig" />
  </ItemGroup>
  <ItemGroup>
    <None Remove=".editorconfig" />
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

我不知道为什么插入这个,但它解决了我的问题。


Met*_*ose 10

事实证明,问题在于尝试.editorconfig从项目中引用文件。我删除了引用,只是将该文件作为解决方案项保留在解决方案的根目录中。我从那里开始大部分设置都工作得很好,但我有一些 StyleCop 严重性设置没有被分析器正确拾取。

为了解决这个问题,我改为GlobalSuppressions.cs单独使用每个项目的文件。我可能可以将它们捆绑在一起并像处理文件一样引用它们stylecop.json,但我认为限制抑制范围可能更合适。

  • 实际上,您应该能够添加嵌套在子文件夹中的特定于项目的“.editorconfig”文件,只需_不_指定“root = true”选项([参考](https://learn.microsoft.com/it-it/visualstudio /ide/create-portable-custom-editor-options?view=vs-2019#file-hierarchy-and-precedence)) (3认同)
  • 是的,我理解这个问题,并且您的解决方案工作正常。我指出,为了提高一致性,您可以通过使用项目中未引用的根“.editorconfig”(就像您所做的那样)和内部嵌套的“.editorconfig”文件来坚持使用单一类型的配置文件(EditorConfig)每个需要调整设置的项目,避免使用“GlobalSuppressions.cs”。 (2认同)