I am building an extension to do a custom build of my visual studio projects. For this I need to know the name of my project I have selected. How will I be able to get this ?I am writing my plugin in C#.I use visual studio 2017.
You can use the following code to get the current project hierarchy. I got it from here.
IntPtr hierarchyPtr, selectionContainerPtr;
Object prjItemObject = null;
IVsMultiItemSelect mis;
uint prjItemId;
IVsMonitorSelection monitorSelection = (IVsMonitorSelection) Package.GetGlobalService(typeof(SVsShellMonitorSelection));
monitorSelection.GetCurrentSelection(out hierarchyPtr, out prjItemId, out mis, out selectionContainerPtr);
IVsHierarchy selectedHierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)) asIVsHierarchy;
if (selectedHierarchy != null)
{
ErrorHandler.ThrowOnFailure(selectedHierarchy.GetProperty(prjItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out prjItemObject));
}
var projectItem = objProj as EnvDTE.ProjectItem;
Please check this discussion if you like to know more in detail.