Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"CS8700: Multiple analyzer config files cannot be in the same directory" but only one StyleCop file

I'm trying to learn to use StyleCop on a personal project. It's not a very big one, and the solution structure is below:

- 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)

And here is how the folders themselves are structured:

- 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

Everything worked prior to adding the file for StyleCop. I could build and test just fine in Visual Studio. For whatever reason, adding the file for StyleCop (and maybe the .editorconfig file) seems to have caused this error on build:

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]

As far as I understand, the StyleCop file is the only analyzer file and it's referenced in multiple places. Does the .editorconfig somehow count as another analyzer file? If so, how do I get them to play nice?

Suppressing the error in .editorconfig does nothing. I haven't been able to find any helpful documentation when searching the error alone either.

like image 261
Metomorphose Avatar asked Jun 09 '20 04:06

Metomorphose


2 Answers

Just for other googler's reference.

I used NiccoMlt's structure, but encountered CS8700. I solved this by removing the following from the problematic project file.

  <ItemGroup>
    <EditorConfigFiles Include=".editorconfig" />
  </ItemGroup>
  <ItemGroup>
    <None Remove=".editorconfig" />
  </ItemGroup>

I don't know why this is inserted, but it solved my problem.

like image 156
jeiea Avatar answered Nov 16 '22 03:11

jeiea


Turns out the issue is trying to reference the .editorconfig file from the projects. I deleted the references and just left the file as a solution item in the root of the solution. Most of the settings I have worked fine from there, but I had some StyleCop severity settings that weren't getting picked up properly for the analyzer.

To fix that, I changed to using GlobalSuppressions.cs files for each project individually. I could probably have bundled these together and referenced them like I'm doing with the stylecop.json file, but decided that limiting the suppression scopes was probably more appropriate.

like image 7
Metomorphose Avatar answered Nov 16 '22 03:11

Metomorphose