1

I have created an integration test project to test VS Extension. If I run the tests from the Visual Studio IDE, all tests are running just fine and every method spawns a new VS IDE. The test methods are marked with the following attributes:

[HostType("VS IDE")]
[TestMethod]
public void TestWhateverMethod() { ... }

However if I try to automate the tests, and run them from commandline via MSTest (or VSTest) I got the following error message, for the tests that are hosted inside the VS IDE:

The host type 'VS IDE' cannot be loaded for the following reason: The key 'VS IDE' cannot be found. Make sure that the appropriate host adapter is installed on the machine.

Therefore I tried to find the solution at: MSDN - How to: Install a Host Adapter. But it is only documented for VS2005 and 2008.

I would like to ask for directions regarding VS 2013, where can I found out more? Or what am I missing? Which is the proper way to run integration tests from outside the VS IDE? How one can host an IDE programmatically?

Thank you in advance!

kurtyka
  • 81
  • 8

1 Answers1

3

I realized how to do it, without using the HostType attribute. Hopefully the following code snippet can help out others as well:

Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true);    
DTE env = Activator.CreateInstance(visualStudioType, true) as DTE;

This will get the type of the VS, with the specified version and will throw an exception on error. The DTE will be the interface of the EnvDTE, that one can use.

To get services, do the following, e.g. to get the UI Shell:

ServiceProvider serviceProvider = new ServiceProvider(env as 
Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
IVsUIShell uiShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell));

One should keep track of the services, get the rcw handle and properly release the COM object afterwards the usage.

kurtyka
  • 81
  • 8