0

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
        }
    }
}
Tomasz Maczyński
  • 973
  • 10
  • 24
  • Could you post some code? That would help answering your question. – Tamas Nov 06 '15 at 14:36
  • Yes, I have added some code there. – shekhar kumar Nov 06 '15 at 15:26
  • Your code seems good. Although we don't know how you register your `CodeAction`. You could try to reset your VS experimental instance, or uninstall the VSIX from it, and then redeploy again. – Tamas Nov 06 '15 at 15:55
  • I did, the same code fix provider works very fine when I am creating a project using template Analyzer with codefix(Nuget + VSIX){ Extensibility -->Analyzer with codefix(Nuget + VSIX) }. But it does give this kind of behaviour when i am using template VSIX Project.{Extensibility--> VSIX Project} and in this i am adding the analyzer library in VSIX project. – shekhar kumar Nov 06 '15 at 16:08
  • Probably the MEF extension is not registered, check out the vsixmanifest file for differences. – Tamas Nov 06 '15 at 16:12
  • Indeed, share out your .vsixmanifest. – Jason Malinowski Nov 06 '15 at 19:05
  • Thanks Tamas -Sonar Source Team it worked for me. I had to refer MEF Component in my main vsix. VSIXManifest -->Asset--> Add MEF component and that's It. – shekhar kumar Nov 09 '15 at 13:23
  • Glad I could help. I'll add the comment as an answer too. – Tamas Nov 12 '15 at 19:32

1 Answers1

1

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

Tamas
  • 6,260
  • 19
  • 30