-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do i disable StyleCop for a project or whole solution? #2278
Comments
It sounds like you are using what we refer to as StyleCop Classic - the original StyleCop before it was rewritten for the new C# compiler. If that is the case, you'd have to check with the original project (I'm not sure if/where it's still around). If you are using StyleCop Analyzers, then it's only applied to projects that have the StyleCop.Analyzers NuGet package installed. Uninstalling the package from a project will disable the analysis for that project. |
Thanks for the reply @sharwell, i'm using StyleCop Analyzers. Was hoping it would be possible to disable during builds with a flag. It has a bit too much impact on Debug build time, unless one has a powerful CPU. |
@Robban1980 Perhaps you are interested in #1711? |
@sharwell "Uninstalling the package from a project will disable the analysis for that project" I would say there is a bug here. |
@Mattacks and @sharwell we are experiencing the same issue. In our situation, We have a .Net Core project in VS2017 which has StyleCop.Analyzers package installed. Then we have a second .Net Core xUnit project where we don't want that being StyleCopped. However since we have to reference the first project apparently the Analyzer will get enabled as soon as you reference a project which has the Analyzer package installed. Is there any workaround? |
@Mattacks and @aboo, make sure to report this to the Roslyn team (https://github.com/dotnet/roslyn) if it hasn't already been done. Individual rules are supposed to be activated depending on if the analyzer is referenced in a project and if the rule is configured to be run according to the ruleset file, so if for example StyleCop Analyzers are getting executed on a project it's not configured for then that indicates a problem somewhere else, probably in Roslyn itself. As a workaround, you could try configuring a different ruleset file for the test project with all rules turned off. See if that works. Otherwise, you could try to suppress all StyleCop warnings in that Project (Project properties -> Build -> Suppress warnings). No fun, but it might be ok as a work-around. Other than that, I can't think of anything to get rid of them completely. What I think you really should do, is to actually have StyleCop referenced in the test project as well, but possibly disable some rules that you think is unnecessary by using another ruleset file for that project. Most of our rules are equally applicable to test code... But that's only a suggestion :-) |
Thanks @bjornhellander. We've already done the workaround of having another ruleset for the test projects. I will follow this up with Roslyn team. |
@aboo - any update on this? I looked at Roslyn issues but didn't see any mention of this issue. Did you log an issue there? |
@ryantrem Nah I was too lazy to file an issue :) We've decided to use different rule-set for our test projects. The reason is that we realized that we need some of the rules but not all of them. |
I was running into this as well and finally managed to figure out how to exclude StyleCop.Analyzers where I needed to. Similar to @aboo I have an xunit project (which I don't want analyzed) that references/consumes my class library (which I do want analyzed). I'm using .NET Core on Mac and just had to make sure that when including the package in my class library, I explicitly set the
What I found strange was that according to the Microsoft docs, I'm a little new to NuGet, Roslyn, etc. but based on the documentation I wouldn't have expected this to be necessary. Could it be that Roslyn doesn't consider StyleCop.Analyzers as an "analyzer"? I'm happy to file something at Roslyn to get this straightened out because it did cause me quite a few headaches... |
I ended up not logging an issue with Roslyn because I was not able to repro this after updating to Visual Studio 2017, so I assumed it had been fixed. @powellcj12 which version of VS are you using? I thought was a NuGetv 4 feature and that NuGet v4 was only included in VS2017, but I could be wrong... |
@ryantrem I'm on a Mac just using the dotnet CLI (v1.0.1) which claims to be using v4.0.0.0 of NuGet CLI:
But I think that's just the version of the CLI tools, not the library/binaries themselves. Based on this article, it seems like MSBuild is now really the thing responsible for restoring packages.
This all just came with the .NET Core 1.1 SDK that I installed, which I believe is also what's included in VS2017. |
If I am understanding correctly I see some issues by StyleCop.Analyzers being a PackageReference in a CSProj file.
From what I have read and seen it seems like making this a NuGet package doesn't make sense. Feels like an open source project that releases their API's via NuGet and uses StyleCop.Analyzers will make the API dependencies to heavy and most likely cause the project to not be taken up as quickly or at all. It seems like either PrivateAssets set to All shouldn't be required, or should be set automatically. Plus it seems like PrivateAssets set to All can be defeated as reported in this Issue: dotnet/sdk#1808 Is there something missing? Is there no way for a NuGet package when referenced to ensure it is always set to be Private for its direct consumer? Therefore my big question is HOW can I use the new StyleCop Analyzers without making it a dependency on my projects? Or is the only way to use the NuGet package and then manually have to change a setting on its PackageReference on CSProj file? Since DotNet SDK Issue 1808 is still open is this an issue that could cause issues for consumers of NuGet packages that use StyleCopy.Analyzers even when they set SyleCop to be private? |
This will only happen if the package was created with this dependency. The
This should only happen in cases where it's desired, e.g. a NuGet package whose purpose is to install and configure StyleCop Analyzers for a specific team/company. If you are seeing this as a transitive dependency of an unrelated library, it means the library was incorrectly authored (the
I believe this applies only to assembly references, and not to analyzers.
We've taken measures to the extent we know how. If you find a better way to do this please let us know. StyleCopAnalyzers/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/StyleCop.Analyzers.nuspec Line 16 in 1c3c14d
Beyond this, our "hands are tied" so to speak by the implementation of NuGet itself. |
Looks like there is an open issue being worked on to allow this. Looks like some very smart people want developmentDependency in the nuspec to trigger the setting of PrivateAssess to all when the package is added. Looks like they are trying to get this in... its a very long thread. However, when they implement this and release it your nuspec should be perfectly fine as is. Thanks for the response. |
I have a similar problem. |
I removed obj folders and it's helped me )) |
Thanks for all the information on this post. We ran into a similar problem . Adding |
Is there a way to disable the rules for a |
I'm having the issue of not being able to disable stylecop for individual projects or a whole solution. Only help online i can find is for previous non versions of StyleCop. Anyone have any tips on how to do it?
The text was updated successfully, but these errors were encountered: