What is the minimal working IVsTextViewCreationListener implementation?
Asked Answered
P

1

6

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?

Patroclus answered 14/9, 2014 at 17:50 Comment(0)
S
5

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>
Sociopath answered 15/9, 2014 at 5:46 Comment(1)
It was the MefComponent that I was missing. Thanks.Aryl

© 2022 - 2024 — McMap. All rights reserved.