Helpful VSIP Solution Explorer knowledge

I have been reading some posts and blogs by an Extensibility Guru: Chetan Chudasama

And through his info ( all vb.net stuff ) I got a few helper things.

1) Finding the Full Path to the Project of the current Selected Item.

   1:  UIHierarchy UIH = _applicationObject.ToolWindows.SolutionExplorer;
   2:   
   3:  // Get the first selected item, intended for right click on slnExplorer
   4:  UIHierarchyItem fld = (UIHierarchyItem)((System.Array)UIH.SelectedItems).GetValue(0);
   5:   
   6:  // cast and retrieve the project item for that object.
   7:  ProjectItem prj = fld.Object as ProjectItem;
   8:   
   9:  // in my case i wanted to make sure we are dealing with a physical folder
  10:  // however you may just want the path, so keep reading.
  11:  if (prj.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
  12:  {
  13:     string strProjPath = prj.ContainingProject.Properties.Item("FullPath").Value.ToString();
  14:     string strFolderPath = strProjPath + "/" + fld.Name;
  15:   
  16:     System.Windows.Forms.MessageBox.Show(strFolderPath);
  17:  }
That shows you how to get the project path, which is the only item I have found that allows you to access Path.
From there you have to manually use the hierarchy tree to find your items.
Here are two more methods, I borrowed from Chetan from the MSDN forums, which allow you to decode .Kind into
what kind of object you have retrieved. A few of the more interesting ones I have used:
  • vsProjectItemKindPhysicalFolder

  • vsProjectItemKindPhysicalFile

  • vsProjectItemKindVirtualFolder

 
 
   1:  private string DecodeProjectItemKind(string sProjectItemKind)
   2:          {
   3:             string sResult;
   4:           
   5:             switch(sProjectItemKind)
   6:             {
   7:                 case EnvDTE.Constants.vsProjectItemKindMisc:
   8:                   sResult = "EnvDTE.Constants.vsProjectItemKindMisc";
   9:                   break;
  10:                case EnvDTE.Constants.vsProjectItemKindPhysicalFile:
  11:                   sResult = "EnvDTE.Constants.vsProjectItemKindPhysicalFile";
  12:                   break;
  13:                case EnvDTE.Constants.vsProjectItemKindPhysicalFolder:
  14:                   sResult = "EnvDTE.Constants.vsProjectItemKindPhysicalFolder";
  15:                   break;
  16:                case EnvDTE.Constants.vsProjectItemKindSolutionItems:
  17:                   sResult = "EnvDTE.Constants.vsProjectItemKindSolutionItems";
  18:                   break;
  19:                case EnvDTE.Constants.vsProjectItemKindSubProject:
  20:                   sResult = "EnvDTE.Constants.vsProjectItemKindSubProject";
  21:                   break;
  22:                case EnvDTE.Constants.vsProjectItemKindVirtualFolder:
  23:                   sResult = "EnvDTE.Constants.vsProjectItemKindVirtualFolder";
  24:                   break;
  25:                default:
  26:                   sResult = "";
  27:                   break;
  28:              }
  29:   
  30:              return sResult;
  31:   
  32:          }
  33:   
  34:          private string DecodeProjectKind(string sProjectKind)
  35:          {
  36:              string PROJECT_KIND_ENTERPRISE_PROJECT = "{7D353B21-6E36-11D2-B35A-0000F81F0C06}";
  37:              string PROJECT_KIND_CPLUSPLUS_PROJECT = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
  38:              string PROJECT_KIND_VSNET_SETUP = "{54435603-DBB4-11D2-8724-00A0C9A8B90C}";
  39:   
  40:              string sResult = string.Empty;
  41:   
  42:              switch (sProjectKind.ToUpper())
  43:              {
  44:                  case VSLangProj.PrjKind.prjKindVBProject.ToUpper():
  45:                      sResult = "VSLangProj.PrjKind.prjKindVBProject";
  46:                  case VSLangProj.PrjKind.prjKindCSharpProject.ToUpper():
  47:                      sResult = "VSLangProj.PrjKind.prjKindCSharpProject";
  48:                  case VSLangProj2.PrjKind2.prjKindVJSharpProject:
  49:                      sResult = "VSLangProj2.PrjKind2.prjKindVJSharpProject";
  50:                  case VSLangProj2.PrjKind2.prjKindSDEVBProject:
  51:                      sResult = "VSLangProj2.PrjKind2.prjKindSDEVBProject";
  52:                  case VSLangProj2.PrjKind2.prjKindSDECSharpProject:
  53:                      sResult = "VSLangProj2.PrjKind2.prjKindSDECSharpProject";
  54:                  case EnvDTE.Constants.vsProjectKindMisc.ToUpper():
  55:                      sResult = "EnvDTE.Constants.vsProjectKindMisc";
  56:                  case EnvDTE.Constants.vsProjectKindSolutionItems.ToUpper():
  57:                      sResult = "EnvDTE.Constants.vsProjectKindSolutionItems";
  58:                  case EnvDTE.Constants.vsProjectKindUnmodeled.ToUpper():
  59:                      sResult = "EnvDTE.Constants.vsProjectKindUnmodeled";
  60:                  case VSLangProj.PrjKind.prjKindVSAProject.ToUpper():
  61:                      sResult = "VSLangProj.PrjKind.prjKindVSAProject";
  62:                  case PROJECT_KIND_ENTERPRISE_PROJECT:
  63:                      sResult = "Enterprise project";
  64:                  case PROJECT_KIND_CPLUSPLUS_PROJECT:
  65:                      sResult = "C++ project";
  66:                  case PROJECT_KIND_VSNET_SETUP:
  67:                      sResult = "Setup project";
  68:                  default:
  69:                      sResult = "";
  70:              }
  71:   
  72:              return sResult;
  73:          }
 
Correction: The DecodeProjectKind Method should look like this:

private string DecodeProjectKind(string sProjectKind)

{

string PROJECT_KIND_ENTERPRISE_PROJECT = "{7D353B21-6E36-11D2-B35A-0000F81F0C06}";

string PROJECT_KIND_CPLUSPLUS_PROJECT = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";

string PROJECT_KIND_VSNET_SETUP = "{54435603-DBB4-11D2-8724-00A0C9A8B90C}";

string sResult = string.Empty;

string match = sProjectKind.ToUpper();

if (match == VSLangProj.PrjKind.prjKindVBProject.ToUpper())

sResult = "VSLangProj.PrjKind.prjKindVBProject";

else if (match == VSLangProj.PrjKind.prjKindCSharpProject.ToUpper())

sResult = "VSLangProj.PrjKind.prjKindCSharpProject";

else if (match == VSLangProj2.PrjKind2.prjKindVJSharpProject)

sResult = "VSLangProj2.PrjKind2.prjKindVJSharpProject";

else if (match == VSLangProj2.PrjKind2.prjKindSDEVBProject)

sResult = "VSLangProj2.PrjKind2.prjKindSDEVBProject";

else if (match == VSLangProj2.PrjKind2.prjKindSDECSharpProject)

sResult = "VSLangProj2.PrjKind2.prjKindSDECSharpProject";

else if (match == EnvDTE.Constants.vsProjectKindMisc.ToUpper())

sResult = "EnvDTE.Constants.vsProjectKindMisc";

else if (match == EnvDTE.Constants.vsProjectKindSolutionItems.ToUpper())

sResult = "EnvDTE.Constants.vsProjectKindSolutionItems";

else if (match == EnvDTE.Constants.vsProjectKindUnmodeled.ToUpper())

sResult = "EnvDTE.Constants.vsProjectKindUnmodeled";

else if (match == VSLangProj.PrjKind.prjKindVSAProject.ToUpper())

sResult = "VSLangProj.PrjKind.prjKindVSAProject";

else if (match == PROJECT_KIND_ENTERPRISE_PROJECT)

sResult = "Enterprise project";

else if (match == PROJECT_KIND_CPLUSPLUS_PROJECT)

sResult = "C++ project";

else if (match == PROJECT_KIND_VSNET_SETUP)

sResult = "Setup project";

else

sResult = "";

 

return sResult;

}

Published Monday, June 26, 2006 5:03 PM by jminond
Filed under: , ,

Comments

# DNS - .NET Blog

Tuesday, June 27, 2006 3:25 PM by Jonathan's Blog

I have a new additional blog, that will be focused more on .NET specifics, as well as Extensibility and automation as opposed to this blog that is more Rainbow and Application geared.

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.