【问题标题】:Visual Studio Add-in development - Get directory path within a C++ projectVisual Studio 插件开发 - 获取 C++ 项目中的目录路径
【发布时间】:2010-09-13 00:05:06
【问题描述】:
我目前正在尝试构建一个类似于VSNewFile 的加载项。所以它只是一个简单的扩展,它提供了一种更快的方式来创建新文件。 VSNewFile 的问题在于它不适用于 C++ 项目,我需要它。
这是我的问题:
我无法检索所选目录的绝对路径。我发现的所有样本都是这样的:
(string)((ProjectItem)parent).Properties.Item("FullPath").Value;
虽然这适用于 C# 项目,但它不在 C++ 项目中。在 C++ 项目中,当我选择一个目录时,selectedItem.Project 和 selectedItem.ProjectItem 都是 null。
重要提示:我不是在谈论过滤器!我的意思是真正的目录。
欢迎任何帮助。我已经搜索了几个小时没有成功。
谢谢
【问题讨论】:
标签:
c++
visual-studio
visual-c++
visual-studio-addins
【解决方案1】:
也许这会对遇到同样问题的其他人有所帮助:
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;
}