Automatically run extension code in Visual Studio on startup
Asked Answered
B

3

8

Can I create an extension for Visual Studio that runs in the background as soon as the user opens the Visual Studio IDE? For example, I am building an extension that gets the current active file address in Visual Studio (with C#), but I would like this extension to always run in the background without having to be activated by the user clicking a button or pressing some key combination.

Is this possible, and if so, what is the best way of doing it?

Any help would be greatly appreciated! Regards, Erfan

Behlau answered 5/3, 2015 at 15:47 Comment(1)
Depending upon what you're trying to do, you can specify your extension to load for certain file types.Foozle
P
5

Since you tagged your question with visual-studio-2010 I assume you are working on an "Add-in" rather than a "VSPackage Extensions".

In this case, you can use the OnConnection event handler.

If you are working on a VSPackage Extensions, you can use the attribute ProvideAutoLoad.

Just search for these, you will find sufficient information. Both ways are also described shortly here under "How can I run my add-in code in a VSPackage?"

Penrose answered 5/3, 2015 at 16:24 Comment(0)
O
5

For VS 2010 and higher the recommended extensibility approach is a package (VS 2015 won't allow add-ins).

To get the package loaded when Visual Studio is loaded see HOWTO: Autoload a Visual Studio package.

Once loaded, your package may be interested in two different kind of selection change events:

Overcareful answered 6/3, 2015 at 3:6 Comment(0)
E
4

For Extension add following attribute to Package class, this will load the extension when a solution is not open in visual studio. I have tested this with VS 2015 and 2017.

[ProvideAutoLoad(UIContextGuids80.NoSolution)]
Ellerd answered 2/8, 2017 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.