2014-11-03 79 views
1

我創建了一些visual studio擴展,並以編程方式創建解決方案文件夾。 但我不知道如何從另一個解決方案文件夾創建一個依賴項一個解決方案文件夾? 任何人都可以幫助我解決這個問題嗎?謝謝!解決方案文件夾的依賴關係

|--- SolutionFolder 
|   |--- SolutionFolder 
|   |--- SolutionFolder 
|--- SolutionFolder 

這裏是我的代碼:

(object sender, EventArgs args) => 
{ 
    Guid slnFldrGuid = new Guid("2150E333-8FDC-42A3-9474-1A3956D46DE8"); 
    Guid iidProject = typeof(IVsHierarchy).GUID; 

    IVsSolution solution = GetService<IVsSolution, SVsSolution>(); 
    IVsHierarchy parent = UIShellUtilities.GetSelectedHierarchy(); 
    IVsHierarchy nested = null; 

    IntPtr project = IntPtr.Zero; 
    int canceled = 0; 

    if ((null != solution) && (null != parent)) 
    { 
     IVsProjectFactory factory = null; 

     ErrorHandler.ThrowOnFailure(solution.GetProjectFactory(
      0, new Guid[] { slnFldrGuid }, null, out factory)); 

     try 
     { 
      ErrorHandler.ThrowOnFailure(factory.CreateProject(
       null, null, "New My Folder", 0, ref iidProject, out project, out canceled)); 

      if (project != IntPtr.Zero) 
      { 
       nested = Marshal.GetTypedObjectForIUnknown(project, typeof(IVsHierarchy)) as IVsHierarchy; 

       Debug.Assert(nested != null, "Nested hierarchy could not be created"); 
       Debug.Assert(canceled == 0); 
      } 
     } finally 
     { 
      if (project != IntPtr.Zero) 
       Marshal.Release(project); 
     } 

     uint itemid = VSConstants.VSITEMID_ROOT; 

     // Link into the nested VS hierarchy. 
     //ErrorHandler.ThrowOnFailure(nested.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchy, parent)); 
     //ErrorHandler.ThrowOnFailure(nested.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid, (object)itemid)); 
    }       
} 

回答

相關問題