-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Visual Studio, show error at build time for error diagnostics #1158
Comments
I can confirm this behavior in VS 17.7. My suspicion is that there was some change in a way how the analyzers from extension are handled. Current behavior:
I think I would be the best if you file an issue to VS feedback portal to clarify if my assumption is correct. It's possible that it's a bug and it will be fixed in the future. It's also possible that it's a bug in Roslynator but I would say that it's unlikely in this case. As a side note, I tend to opinion that good practice is to reference analyzers always as nuget, so they are part of the solution and are enforced regardless of the extension installed or not. |
Thank you Josef. I have logged with Visual Studio. Let's keep this open until resolved. https://developercommunity.visualstudio.com/t/Analyzers-from-extensions-not-affecting-/10442691 As a side note, is there any documentation around using the analyzers in the nuget package vs extension? Which project must the nuget be referenced in, how do we get it to affect all projects in a solution? This is why we use the extension so it applies everywhere. |
This behavior is by design. See dotnet/roslyn#8068. |
Thank you for the clarification. What is the point then of the VS extension? Also this means that every single project we have in our solution needs to reference the analyzers nuget package? That's why we install the extension into VS so that it applies globally to all projects. Our thinking was that even if someone doesn't have the extension installed, or using CLI, they would just miss out on those analyzers. |
Many analyzer projects do not distribute as a VS extension at all. There are some edge cases where a Roslyn extension might want to be an extension, such as a collection of code refactoring providers (not analyzers) which would never be needed during a build and don't necessarily apply to all users working on the project.
Yes, but it doesn't mean every project file has to have a direct reference. You can place the reference in Directory.Build.props or Directory.Build.targets and it will apply to all projects underneath that folder. For example:
Yes, this is exactly why we do not include them. If we included them, we would have to explain to all these users why sometimes a build will break for some users on a project, and other times it will not. Builds are expected to be consistent. |
Great input, thank you. |
@sharwell was faster then me to answer 😄. VS extension contains not only analyzers but also refactorings and fixes for compiler diagnostics (CS....). These code analysis tools are distributed only as a part of VS (Code) extension. Regarding the analyzers: Over the years it turned out that including analyzers in the extension is a bad practice. The intention was good - to have analyzers available for every solution in VS. But the reality is that you want enforce analyzer rules regardless of the extension installed or the IDE. The only clear solution to this issue is to remove analyzers from the VS (Code) extension. This will be done probably as a part of next major release of Roslynator (when major version of VS is released). |
@josefpihrt so to confirm:
And you're good to go? |
Yes (assuming that Directory.Build.props is at the repo root directory or There is one more thing which is not necessary but it's better to do while the analyzers are part of the extension: You can disable analyzers from the extension to prevent them from running twice by adding following option to your default configuration file: roslynator_analyzers.enabled_by_default = false Default configuration is described here. |
follow up #1172 |
Product and Version Used:
VS 17.7.0
Roslynator 4.4.0
Steps to Reproduce:
In my .editorconfig I have the following rules set:
In a .cs file to test, these rules show up as errors correctly:
However, when the project/solution is built, the build succeeds.
There appears to be a disconnect with Roslynator diagnostics vs the MS ones. If I configure one as an error, it fails the build. For example:
dotnet_diagnostic.CA1841.severity = error
Expected Behavior:
I would expect that, at build time, for analyzers set to
warning
anderror
to show up in the build logs. And especially for items marked aserror
to halt the build.My .editorconfig file: .editorconfig.txt
The text was updated successfully, but these errors were encountered: