Visual Studio Add-in development - Get directory path within a C++ project
i'm currently trying to build an add-in which is similar to VSNewFile. So it's just a simple extension which provides a faster way to create new files. The problem with VSNewFile is that it doesn't work for C++ projects and i need it for that.
Here is my problem: I'm unable to retrieve the absolute path of a selected directory. All samples i've found were something like that:(string)((ProjectItem)parent).Properties.Item("FullPath").Value;
While this is working in a C# project it isn't in a C++ project. In an C++ project selectedItem.Project
and selectedItem.ProjectItem
are both null
when i select a directory.
Important: I'm not talking about filters! I mean real directories.
Any help is welcome. I've searched for hours now without success开发者_C百科.
ThanksMaybe this will help anyone else who got the same problem:
http://social.msdn.microsoft.com/forums/en-US/vsx/thread/bd738463-ba24-4880-beea-f3ec110d981e
// Subscribe to the SVsShellMonitorSelection service somewhere:
public void mySetupMethod()
{
IVsMonitorSelection monitorSelection =
(IVsMonitorSelection)Package.GetGlobalService(
typeof(SVsShellMonitorSelection));
monitorSelection.AdviseSelectionEvents(this, out cookie);
}
// This class (as used in AdviseSelection) must implement the IVsSelectionEvents interface
// To get the folder path use the following
public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld,
IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld,
IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
{
string fullPath;
// Get the full path
pHierNew.GetCanonicalName(itemidNew, out fullPath);
// Do something with the path...
return VSConstants.S_OK;
}
精彩评论