shekhar kumar
shekhar kumar

Reputation: 3

I am able to get the Roslyn analyzer for my extension but failed to get the codeFix provider for the same diagnostics

I have created a vsix project which is referencing a Roslyn analyzer and a code fix library. I am able to get the analyzer for my extension but failed to get the code fix provider for the same diagnostics.

Analyzer

namespace CSharpDiagnostics
{
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class AsyncMethodNameAnalyzer : SyntaxNodeAnalyzer
    {
        // Analyzer code, which I am able to debug and working fine.
    }
}

CodeFix Provider

This is a code fix for the AsyncMethodNameAnalyzer mentioned above. It looks like the Export attribute is not functioning properly for it.

namespace CSharpDiagnostics
{
    [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AsyncMethodNameCodeFix))]
    public class AsyncMethodNameCodeFix : CodeFixProvider
    {
        public override ImmutableArray<string> FixableDiagnosticIds
        {
            get
            {
                return ImmutableArray.Create(AsyncMethodNameAnalyzer.DiagnosticId);
            }
        }

        public sealed override FixAllProvider GetFixAllProvider()
        {
            return WellKnownFixAllProviders.BatchFixer;
        }

        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            // My code for fix provider
        }
    }
}

Upvotes: 0

Views: 356

Answers (1)

Tamas
Tamas

Reputation: 6420

You have to make sure that the MEF extension is registered in your vsixmanifest file.

Upvotes: 1

Related Questions