Search code examples
c#wpfvisual-studio-2010start-page

How to Open a Solution from a Custom VS2010 Start Page


I'm writing a custom WPF Start Page for VS2010. I have it displaying a list of common solutions used by me in a View.

Now, I want to open the Solution in VS when selected.

Any ideas? I'm looking at the DTE stuff, but having very little success. Before I dig too deeply, is DTE the right way forward, or is there another way?


Solution

  • I found the solution.

    In the Utilities class generated by the Visual Studio Template there is the following static method:

    public static DTE2 GetDTE(object dataContext)
    {
        ICustomTypeDescriptor typeDescriptor = dataContext as ICustomTypeDescriptor;
        Debug.Assert(typeDescriptor != null, "Could not get ICustomTypeDescriptor from dataContext. Was the Start Page tool window DataContext overwritten?");
        PropertyDescriptorCollection propertyCollection = typeDescriptor.GetProperties();
        return propertyCollection.Find("DTE", false).GetValue(dataContext) as DTE2;
    }
    

    By passing in the DataContext from my Control into the GetDTE() method I can do this:

    var dte = Utilities.GetDTE(dataContext);
    dte.Solution.Open(fullPathToSolution);