-
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
Compiler does not report unused imports when XML doc comments are disabled #41640
Comments
I thought we had a flag here to at least tell the compiler to bind the docs, even if we don't want errors or xml generation for them. That way our symbolic information is all correct, regardless of what emit behavior the user specifies. |
@mavasani The underlying compiler diagnostic (CS8019) is not accurate if XML documentation parsing is disabled. Currently the project can only specify |
Ah, maybe in that case we can enhance the unused usings analyzer to report a separate diagnostic when IDE0005 is bumped to warning/error but documentation mode is None, which informs the user that XML documentation comments need to be enabled for the project to get accurate IDE0005 on CI. Does that sound reasonable? If so, we can move this issue to Area-IDE. |
For people wondering why command-line/CI builds are letting unused usings through, this is what you need to paste into your csproj or Directory.Build.props after adding <!-- Workaround for https://github.com/dotnet/roslyn/issues/41640 -->
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
</PropertyGroup> |
…ngs) on build Due to dotnet#41640, enabling IDE0005 on build requires users to enable generation of XML documentation comments. Even though this is documented with a note on IDE0005's [doc page](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0005), we have had numerous reports of users not figuring this out and spending lot of cycles fighting with this, especially given other IDE diagnostics work just fine on build. We have had many user reports of the same: dotnet#58103, dotnet#53720, dotnet#57539, OpenRA/OpenRA#19747 and numerous other offline queries. This change enhances the IDE0005 analyzer to now detect the case when IDE0005 is being reported as a warning or an error in the IDE, but `GenerateDocumentationFile` is `false` for the project, which would mean IDE0005 wouldn't be reported on build. The analyzer reports a special helper diagnostic for this case, which recommends the user to set this property to `true` in their project file to enable IDE0005 on build. This should reduce the pain for customers who try to enforce IDE0005 on build and get hit by this issue.
@justinmchase I wouldn't expect GenerateDocumentationFile to have anything to do with that diagnostic. On a side note, does setting https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#enforcecodestyleinbuild in your csproj help? |
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> Does not cause build errors when the above rule is set to |
I am struggling a bit. When I set to
The only thing that fixes it for me without toggling What am I doing wrong? |
So this works:
But this doesnt:
@sharwell what am I doing wrong? |
@VictorioBerra I'm guessing you have that line earlier in the build than wherever |
@VictorioBerra $(Language) is not supported in a Directory.Build.props but only in a Directory.Build.targets file. |
If I remember right, I've used |
…teDocumentationFile: Set MSBuild property 'GenerateDocumentationFile' to 'true' in project file to enable IDE0005 (Remove unnecessary usings/imports) on build (dotnet/roslyn#41640) [/home/runner/work/osu-framework-microphone/osu-framework-microphone/osu.Framework.Microphone/osu.Framework.Microphone.csproj]" error Also see: https://github.com/ppy/osu-framework/pull/6169/files
I don't like this one but because I do not want things like documentation files to be output when: I build an winforms project where everything is "internal" visibility
And yes I have an application of this type and the csc warning from doing this annoys me a lot. As such I feel that forcing a warning for people who WANT to enforce no documentation file to be generated would be a must, or at least a switch to skip copy on it from the intermediate -> output directory. Edit:
|
This is intentional, similar to what would happen if you add the following to your project: <ItemGroup>
<Compile Include="ThisFileDoesNotExist.cs"/>
</ItemGroup> By explicitly providing the compiler with an instruction to enforce IDE0005 at warning (or greater) severity, and then removing its ability to do so by disabling the documentation file output, the project is in an invalid state. Multiple solutions are provided above to return the project to a valid state (either disable the IDE0005 analysis by setting the severity to suggestion or lower, or enable the documentation output). |
Which is funny because I never really enabled that analysis on it specifically for outside of Visual Studio 😄. |
IDE0005 is not enabled at warning severity or greater by default. There are many ways a project could be modified to increase its severity, so without a binlog its difficult to be more specific. |
@RenderMichael instead of disabling |
Thanks for the response. It's not clear from the user side that IDE0005 requires documentation files to be generated. Can the error message include something along the lines of |
Have to enable GenerateDocumentationFile for test csproj to work around dotnet/roslyn#41640
This PR addresses or suppresses all (but one) of the warnings. Some existed prior to .NET 8 in #966, but the majority were introduced in #966. | Code | Description | Outcome | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | | CA1724 | Type names should not match namespaces | Suppressed in limited cases for `Pickers` and `Store` | | CA1859 | Use concrete types when possible for improved performance | Fixed in production code, suppressed for tests | | CA1861 | Avoid constant arrays as arguments | Suppressed for tests | | CA1862 | Use the 'StringComparison' method overloads to perform case-insensitive string comparisons | Fixed | | CA2000 | Dispose objects before losing scope | Fixed | | CA2213 | Disposable fields should be disposed | Fixed, suppressed for most tests | | CA5392 | Use DefaultDllImportSearchPaths attribute for P/Invokes | Fixed | | CS0108 | 'TestProxyLayoutEngine.InnerLayoutEngine' hides inherited member 'BaseProxyLayoutEngine.InnerLayoutEngine'. Use the new keyword if hiding was intended. | Fixed | | IDE0005 | Remove unnecessary using directives | Fixed | | IDE0028 | Use collection initializers or expressions | Fixed | | IDE0290 | Use primary constructor | Fixed | | IDE0300 | Use collection expression for array | Fixed | | IDE0301 | Use collection expression for empty | Fixed | | IDE0303 | Use collection expression for Create() | Fixed | | IDE0305 | Use collection expression for fluent | Fixed | | SYSLIB0051 | Legacy serialization support APIs are obsolete | Fixed | | xUnit1048 | Avoid using 'async void' for test methods as it is deprecated in xUnit.net v3 | Fixed | | - | Set MSBuild property 'GenerateDocumentationFile' to 'true' in project file to enable IDE0005 (Remove unnecessary usings/imports) on build (dotnet/roslyn#41640) | Fixed | The only remaining warning is: ```log NETSDK1206 Found version-specific or distribution-specific runtime identifier(s): win10-arm64, win10-x64, win10-x86. Affected libraries: Microsoft.WindowsAppSDK. In .NET 8.0 and higher, assets for version-specific and distribution-specific runtime identifiers will not be found by default. See https://aka.ms/dotnet/rid-usage for details. ``` I also cheekily decreased the default focus indicator size in this PR.
* Enable EnforceCodeStyleInBuild and fix findings Have to enable GenerateDocumentationFile for test csproj to work around dotnet/roslyn#41640 Fix up code generated by roslyn fixer Don't consider GlobalSuppressions.cs or TrimmingAttributes.cs --------- Co-authored-by: Keegan Caruso <[email protected]>
#41363 moves the "Remove unnecessary usings" IDE analyzer into the CodeStyle NuGet package, so this analyzer can execute on CI. This analyzer depends on the compiler layer reporting hidden diagnostics (
CS8019
) for unused usings:roslyn/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Helpers/RemoveUnnecessaryImports/CSharpUnnecessaryImportsProvider.cs
Lines 23 to 48 in 2b12b9f
However, the logic in compiler layer that reports these unused usings is guarded on XML doc comments being enabled:
roslyn/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
Lines 2116 to 2140 in 41bc895
This logic seems to work fine for IDE-only purpose as XML doc comments are explicitly force enabled in the IDE. However, it breaks down for this same analyzer from command line when XML doc comments are disabled.
I presume this was done as a performance optimization to prevent this code from executing on default command line builds, when XML doc comments are disabled. I see 2 options to retain this performance optimization while fixing the command line case:
CS8019
diagnostics.IMO, option 1. is a much better approach.
The text was updated successfully, but these errors were encountered: