简体   繁体   English

在不使用 item.Document.FullName 的情况下获取 ProjectItem 路径

[英]Get ProjectItem path without using item.Document.FullName

I have a visual studio add-in project where I must iterate through the current project's items, utilizing the absolute (or relative) path to those files.我有一个 Visual Studio 插件项目,我必须使用这些文件的绝对(或相对)路径来遍历当前项目的项目。

The item.Document.FullName works, but only for files that are currently opened. item.Document.FullName有效,但仅适用于当前打开的文件。

Is there any other way to access this information in the DTE object?有没有其他方法可以访问DTE object 中的这些信息?

Is this what you're looking for?这是你要找的吗?

myProjectItem.Properties.Item("FullPath").Value

Even I was looking for a solution to get the project name based on the document or file Name.甚至我也在寻找一种解决方案来根据文档或文件名获取项目名称。 I found it by using the DTE object.我通过使用DTE object 找到了它。 Initialized the DTE object like the code shown below.初始化DTE object,如下所示。

EnvDTE80.DTE2 objDTE = this.GetService(typeof(SDTE)) as EnvDTE80.DTE2;

Then I used following code, to get the name of the project.然后我使用以下代码来获取项目的名称。

var projectItem = objDTE.Solution.FindProjectItem(document);
var projectUniqueName = projectItem.ContainingProject.UniqueName;

We found that, unless we wanted to parse the XML project files ourselves, you have to first load any unloaded projects.我们发现,除非我们想自己解析 XML 项目文件,否则您必须首先加载任何已卸载的项目。

We record the list and unload them again afterwards so the only issue is the time it takes to load them.我们记录列表并在之后再次卸载它们,因此唯一的问题是加载它们所需的时间。

ProjectItem.FileNames is a collection that represents the full paths of the associated files ProjectItem.FileNames是一个集合,表示关联文件的完整路径

For example if you have webform item called "MyWebForm" you can get from ProjectItem.FileNames the full path of the MyWebForm.ascx file an the full path name of the MyWebForm.ascx.cs (CodeBehind) file例如,如果您有名为“MyWebForm”的网络表单项,您可以从ProjectItem.FileNames获取 MyWebForm.ascx 文件的完整路径以及 MyWebForm.ascx.cs (CodeBehind) 文件的完整路径名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM