C# 如何从自定义VS2010起始页打开解决方案
我正在为VS2010编写一个自定义WPF起始页。我让它在视图中显示我使用的常见解决方案列表 现在,我想在选中时在VS中打开解决方案C# 如何从自定义VS2010起始页打开解决方案,c#,wpf,visual-studio-2010,start-page,C#,Wpf,Visual Studio 2010,Start Page,我正在为VS2010编写一个自定义WPF起始页。我让它在视图中显示我使用的常见解决方案列表 现在,我想在选中时在VS中打开解决方案 有什么想法吗?我正在研究DTE的东西,但几乎没有成功。在我深入挖掘之前,DTE是正确的前进方向,还是有其他方法?您不能简单地以解决方案的路径作为参数来运行它吗 比如: ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = vsdir; startInfo.Arguments
有什么想法吗?我正在研究DTE的东西,但几乎没有成功。在我深入挖掘之前,DTE是正确的前进方向,还是有其他方法?您不能简单地以解决方案的路径作为参数来运行它吗 比如:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = vsdir;
startInfo.Arguments = pathtosolution;
Process.Start(startInfo);
(如果我没弄错的话)我找到了解决办法
在Visual Studio模板生成的Utilities类中,有以下静态方法:
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;
}
通过将DataContext从我的控件传递到GetDTE()方法,我可以做到:
var dte = Utilities.GetDTE(dataContext);
dte.Solution.Open(fullPathToSolution);
不,因为我已经在VisualStudio中,我不想生成新实例。