Closed fossbrandon closed 2 years ago
I did more experimenting and I can't get these warnings to show up when doing dotnet build
with the command line. This could be a Visual Studio bug then but it seems odd that I only seem to get those warnings when I update this package to the newest version. Something to look into at least.
Interesting. I've seen other warnings (also very inconsistently) but not this one. Building analyzers is unfortunately such a mess.
Are all the warnings you get the same as the first one? As in, is the error the same?
Also, do CliFx analyzers work despite the warnings?
So it looks like there are two Microsoft.CodeAnalysis.CSharp
assemblies:
For some reason, unrelated analyzers (StyleCop, Roslynator in your case) are binding to CliFx's instance of Microsoft.CodeAnalysis.CSharp
instead of the default one. My assumption is that VS loads all analyzers in the same application domain and that's why the assembly confusion happens (it's also why the order may be different, it depends on which assembler gets picked first). And then dotnet build
probably loads each analyzer independently.
That would make sense because every time I rebuild, it gives me a different amount of warnings. It shows anywhere between 33 warnings to 150+ warnings.
They all look like the warning in my initial post, but randomly I get a different error like the middle one in this screenshot.
The CliFx analyzer seem to still be working:
I wonder what's the best thing to do in this case. I'm packaging Microsoft.CodeAnalysis.CSharp
to ensure that it's available in that specific version. Relying on pre-installed version is risky because it may be different depending on the version of IDE/SDK installed and potentially a million other factors.
Looks like StyleCop's approach is just to use the oldest version of the library :/
I don't like that haha. Roslynator uses a fairly recent version it seems. https://github.com/JosefPihrt/Roslynator/blob/master/src/Analyzers/Analyzers.csproj#:~:text=%3CPackageReference%20Include%3D%22Microsoft.CodeAnalysis.CSharp%22%20Version%3D%224.0.1%22%20/%3E
Found this on someone's blog:
Amazing 🙃
@fossbrandon I've pushed a pre-release version here: https://www.nuget.org/packages/CliFx/2.2.4-test
Can you test that:
After upgrading, all the warnings are gone!
The CliFx analyzer still seems to work and I was able to get some errors from stylecop so I believe my other analyzers still work as well.
Thanks for looking into this so quick!
Great! I'll push a stable release then
Version
2.2.3
Details
I upgraded from CliFx version 2.2.2 to version 2.2.3 because I wanted those fixes for
IConsole.ReadKey()
, however when I rebuild my solution, it results in lots ofAD0001
analyzer warnings each which look like it originates from the CliFx analyzer.Here is an example of one of the warnings:
Each warning follows a similar format.
I've tried the following to remove the warnings with no success:
Has anyone else seen this issue? Downgrading back to version 2.2.2 removes these warnings.
Steps to reproduce