Stylecopanalyzers: Analyzer doesn't read stylecop.json.

Created on 6 Jan 2016  路  7Comments  路  Source: DotNetAnalyzers/StyleCopAnalyzers

Hello, sorry for bringing this one up again as I know it's been addressed a few times, but I'm having issues getting stylecop.json to be recognized by my project. Here's what I've tried:

  1. Adding the file in quick actions and fixing the csproj manually by using the steps at https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md.
  2. Changing the Build Action to be None, Additional Items, and Content; each time unloading and reloading the project. Unforunately, I haven't had success with any of them. I did notice that when I use Additional Items, the Quick Actions no longer suggest an option for me to generate a stylecop.json file for the project. With the other Build Actions, it gives me this suggestion.
  3. Moving the <AdditionalItems /> element into its own <ItemGroup />.

In all cases I still get a quick action that suggests the fix which is to replace my header which looks like this:

// =======================================================================
// <copyright file="AnalyticsDataProvider.cs" company="LAMA, LLC">
// Copyright 2015 Lama, LLC
// </copyright>
// =======================================================================

To this:

// =======================================================================
// <copyright file="AnalyticsDataProvider.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
// =======================================================================

Here's the contents of my stylecop.json file:

{
  "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json"
  "settings": {
    "documentationRules": {
      "companyName": "LAMA, LLC",
      "copyrightText": "Copyright 2015 {companyName}. All rights reserved."
    }
  }
}

I'm using Visual Studio Community 2015, version 4.6.00081 and RC3 of the analyzer. Any ideas are appreciated, thanks!

question resolved

All 7 comments

Can you try AdditionalFiles instead of AdditionalItems?

When you double click on stylecop.json for your project in Solution Explorer, does it open the correct file?

Hello and thanks for the suggestion. Apologies, I meant to say AdditionalFiles in my original post. Here's what I've put in the csproj:

<ItemGroup>
    <AdditionalFiles Include="stylecop.json" />
  </ItemGroup>

When I double click stylecop.json in the solution explorer, it shows the correct file. It's adjacent to the csproj file. Also, I noticed that AdditionalFiles is not an option I can normally select in the Properties window when the file is selected, although it does appear as an option once the csproj is manually updated to include the <AdditionalFiles/> section.

I figured it out, it's because the "$schema" attribute has a syntax error after its value (missing a comma). Thanks!

@DirtyPiece Thanks for following up. I opened #2029 to help address this for future users. :smile:

This issue still exists in .Net core projects.

@bpraveen4u can you file a new issue for the behavior you are observing?

This issue still exists in .Net core projects.

Issue resolved. It was because of stylecop.json not well formed. missing one flower braces '}'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kindermannhubert picture kindermannhubert  路  6Comments

snowjim picture snowjim  路  6Comments

patriksvensson picture patriksvensson  路  6Comments

Onzi12 picture Onzi12  路  4Comments

MartyIX picture MartyIX  路  5Comments