Skip to content

Test With...VS SDK

Jamie Cansdale edited this page Jul 24, 2018 · 4 revisions

This command allows ad-hoc methods to execute inside the running Visual Studio process and access automation objects, services and MEF components.

DTE Automation Object

  1. Add a reference to EnvDTE.dll
  2. Create the following method
void Hello(DTE dte)
{
    Console.WriteLine($"Hello, {dte.Name}!");
}
  1. Right-click inside Hello and Test With > In-Proc (VS SDK)

You should see

------ Test started: Assembly: EnvDteTests.dll ------

Hello, Microsoft Visual Studio!

1 passed, 0 failed, 0 skipped, took 0.13 seconds (Ghost).

DTE2 Automation Object

You can also access the DTE2 object from EnvDTE80.dll like this:

void Hello(DTE2 dte)
{
    dte.ToolWindows.CommandWindow.Parent.Activate();
    dte.ToolWindows.CommandWindow.SendInput("Help.About", false);
}

UI Thread

If you need to start on the UI thread, you can use the [STAThread] attribute:

[STAThread]
void RunOnUIThread()
{
    Console.WriteLine(Thread.CurrentThread.GetApartmentState());
}

Clone this wiki locally