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

Baris Akar
  • 4,895
  • 1
  • 26
  • 54
Erfan Farhangy
  • 449
  • 2
  • 7
  • 14

3 Answers3

4

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?"

Baris Akar
  • 4,895
  • 1
  • 26
  • 54
4

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:

LadyCailin
  • 849
  • 10
  • 26
Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18
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)]
rxx
  • 744
  • 6
  • 16