Hi Gary,
Here's some sample code. This code is defined within a command handler
(associated with MenuCommand) in my ProjectNode derived class, which is
executed after the hierarchy has been fully built and visualized. This code
is written in C#, primarily against the interop assemblies.
IVsSolution solution =
Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsSolution)) as
IVsSolution;
if (solution != null)
{
IVsHierarchy hierarchy1;
EnvDTE.Project project = (EnvDTE.Project) GetAutomationObject();
string uniqueName = project.UniqueName;
int hr = solution.GetProjectOfUniqueName(uniqueName, out hierarchy1);
//hr == VSConstants.E_FAIL
}
The following code sample was also run to enumerate the number of projects
(hierarchies) in the solution and to determine the project name of each
hierarchy. After running the following code, 1 project hierarchy is returned
in the solution, and the project.uniquename matches the value passed into
GetProjectofUniqueName above.
Guid empty = new Guid();
IEnumHierarchies hierarchies;
hr = solution.GetProjectEnum((uint) __VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref
empty, out hierarchies);
IVsHierarchy[] test = new IVsHierarchy[1];
while (hierarchies.Next(1, test, out fetched) == VSConstants.S_OK)
{
object obj;
hr = test[0].GetProperty(VSConstants.VSITEMID_ROOT,
(int)__VSHPROPID.VSHPROPID_ExtObject, out obj);
EnvDTE.Project proj = (EnvDTE.Project)obj;
System.Diagnostics.Trace.WriteLine(proj.UniqueName);
}
Notre
"Gary Chang[MSFT]" - 02 Sep 2005 09:22 GMT
Hi Notre,
Thanks for your detailed reply!
>string uniqueName = project.UniqueName;
>int hr = solution.GetProjectOfUniqueName(uniqueName, out hierarchy1);
it appears the project.UniqueName doesn't work here, the project path needs
to be relative to the solution. I suggest you can confirm by enumerating
the hierarchies and call the GetUniqueNameOfProject to pass the returned
string to the GetProjectOfUniqueName...
Wish this helps!
Best regards,
Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.
Notre Poubelle - 02 Sep 2005 18:21 GMT
Hi Gary,
This question was answered by one of your colleages in the post
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=81276
Notre
"Gary Chang[MSFT]" - 03 Sep 2005 03:21 GMT
That's Okay, Notre!
I think our VSIP specialist Mike has already give you a more detailed
explanation on this issue:)
Good Luck!
Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.