-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
CS8019 doesn't work during compilation #41391
Comments
@dotnet/roslyn-compiler I saw that reporting these diagnostics is tied to the roslyn/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs Lines 2124 to 2134 in 69d3fb7
However, even with |
I investigated this issue, and found that it is by design (discussion in #23695). Since CS8019 does not filter generated code, it's essentially impossible to increase the severity of this diagnostic and still have a build that works. For example, the {project}.AssemblyInfo.cs files that are generated by default for all SDK projects have unused using directives. Increasing the severity to Error would prevent the build from succeeding, and there would be no way to fix or suppress this case. |
Hi Sam Thank you for your quick response. Any idea of a workaround or a replacemenet to get unused usings reported like I expect it by CS8019? Bascially, I want to let a build fail if there are unused usings. Thanks, Marc |
Currently no such analyzer is provided, but @mavasani is working to make IDE0005 available in command line scenarios. |
I don't have time to wait for a public Analyzer. I need to fail the build during compilation for unneeded using statements now. Where would I go to look at the source code for CS8019 so we can make our own internal version? |
@ericburcham Look in |
@ericburcham The IDE0005 analyzer for remove unnecessary usings is now part of this NuGet package: https://dotnet.myget.org/feed/roslyn/package/nuget/Microsoft.CodeAnalysis.CSharp.CodeStyle/3.6.0-2.20157.5 You can enforce this on command line for your project as follows:
[*.{cs,vb}]
# IDE0005: Remove unnecessary usings/imports
dotnet_diagnostic.IDE0005.severity = warning
|
Sweeeet!
We have an analyzer working, but it will be nice to remove the custom one.
Sent from a mobile device. Please excuse errors / brevity.
On Mar 7, 2020, at 10:29 AM, Manish Vasani ***@***.***> wrote:
@ericburcham The IDE0005 analyzer for remove unnecessary usings is now part of this NuGet package: https://dotnet.myget.org/feed/roslyn/package/nuget/Microsoft.CodeAnalysis.CSharp.CodeStyle/3.6.0-2.20157.5
You can enforce this on command line for your project as follows:
Install the NuGet package to your project
Mark it as a build warning in your repo level editorconfig/ruleset file:
[*.{cs,vb}]
# IDE0005: Remove unnecessary usings/imports
dotnet_diagnostic.IDE0005.severity = warning
Enable XML documentation comments for your project. This is needed to workaround #41640
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@mavasani Are you going to release |
Version Used:
Steps to Reproduce:
Expected Behavior:
Given that the project starts with a Class1.cs file containing unused using directives, compilation should fail.
Actual Behavior:
Compilation succeeds. The VS UI does show the IntelliSense error, however. dotnet build shows no warnings and no errors.
ConsoleApp4.zip
The text was updated successfully, but these errors were encountered: