dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.97k stars 4.03k forks source link

Code fix provider in .NET Standard library is ignored, although the analyzer isn't #21209

Open jamesqo opened 7 years ago

jamesqo commented 7 years ago

Version Used: 1.1.0, VS2017

Steps to Reproduce:

  1. Clone https://github.com/xunit/xunit.analyzers
  2. Go to src/xunit.analyzers/xunit.analyzers.csproj and add <DebugType>full</DebugType> under the <PropertyGroup> node (so breakpoints will work)
  3. Build the repo with powershell ./build.ps1 at the root
  4. Go to any code fix provider and set a breakpoint inside FixableDiagnosticIds
  5. Start an experimental VS instance and open an xUnit test project

Expected Behavior: When one of the analyzers is triggered, e.g. with Assert.Equal(null, foo), the corresponding code fixer that changes it to Assert.Null(foo) should be triggered too.

Actual Behavior: The analyzer is triggered, but the code fix provider is ignored; the breakpoint inside FixableDiagnosticIds is never hit.

sharwell commented 7 years ago

Can you verify that in step 5, the project you open does not have the xunit.analyzers package installed via NuGet? If it does, then the analyzers and code fixes provided by that package will be preferred¹ to the analyzers and code fixes provided by the VSIX.

¹ The rules for "preferred" are fairly complex, but should get some clarity in the 15.5 release from #18818. As a general rule, however, the best way to test your analyzers and fixers will be on projects that don't try to use two versions at the same time.

jamesqo commented 7 years ago

@sharwell The test project does not have xunit.analyzers already installed (it's a dummy test project with only 1 file).

sharwell commented 7 years ago

Did you install the xunit package in the test project? IIRC current versions of that package automatically install the analyzers.

marcind commented 7 years ago

@jamesqo please make sure your project uses xunit.core and xunit.assert packages directly instead of the xunit meta-package.

jamesqo commented 7 years ago

@marcind Tried your suggestions, thank you for the advice. The code fixers still aren't kicking in though. Do they work for you when you try debugging your project on a new xUnit Test Project (.NET Core) template?