问题
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