Ansis Māliņš
Ansis Māliņš

Reputation: 1704

What is the minimal working IVsTextViewCreationListener implementation?

I created a VISX project, and wrote this piece of code:

using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using System.ComponentModel.Composition;

namespace MyExtension
{
    [Export(typeof(IVsTextViewCreationListener))]
    public class Main : IVsTextViewCreationListener
    {
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
        }
    }
}

If I put a breakpoint inside the VsTextViewCreated method, Visual Studio informs me that it will never be hit. Opening files in the second instance of Visual Studio that launches in the debugger indeed does not trigger it.

What am I doing wrong?

Upvotes: 6

Views: 631

Answers (1)

Sergey Vlasov
Sergey Vlasov

Reputation: 27940

You need to specify ContentType and TextViewRole for your class:

[Microsoft.VisualStudio.Utilities.ContentType("text")]
[Microsoft.VisualStudio.Text.Editor.TextViewRole(Microsoft.VisualStudio.Text.Editor.PredefinedTextViewRoles.Editable)]

Also don't forget to declare a MefComponent asset in your extension manifest:

enter image description here

And make sure in .csproj:

<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>

Upvotes: 5

Related Questions