代码之家  ›  专栏  ›  技术社区  ›  DaveShaw Thishin

如何从自定义VS2010起始页打开解决方案

  •  2
  • DaveShaw Thishin  · 技术社区  · 14 年前

    我正在为VS2010编写一个自定义WPF起始页。我让它在视图中显示我使用的常见解决方案列表。

    现在,我想在选中时在VS中打开解决方案。

    有什么想法吗?我在看DTE的东西,但收效甚微。在我深入挖掘之前,DTE是正确的前进之路,还是另有出路?

    2 回复  |  直到 14 年前
        1
  •  3
  •   DaveShaw Thishin    14 年前

    我找到了解决办法。

    在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);
    
        2
  •  0
  •   Blam    14 年前

    你不能简单地以解决方案的路径作为参数来运行它吗?

    比如:

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

    (如果我没听错的话)