How to Open a Solution from a Custom VS2010 Start Page

时光怂恿深爱的人放手 提交于 2019-12-24 01:43:10

问题


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?


回答1:


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);



回答2:


Can't you simply run it with the path to the solution as the argument?

Something like:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = vsdir;
startInfo.Arguments = pathtosolution;
Process.Start(startInfo);

(if I understand you right)



来源:https://stackoverflow.com/questions/3504174/how-to-open-a-solution-from-a-custom-vs2010-start-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!