Get ProjectItem path without using item.Document.F

2019-06-16 12:42发布

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.

The item.Document.FullName works, but only for files that are currently opened.

Is there any other way to access this information in the DTE object?

4条回答
Summer. ? 凉城
2楼-- · 2019-06-16 13:30

Is this what you're looking for?

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

查看更多
可以哭但决不认输i
3楼-- · 2019-06-16 13:31

We found that, unless we wanted to parse the XML project files ourselves, you have to first load any unloaded projects.

We record the list and unload them again afterwards so the only issue is the time it takes to load them.

查看更多
▲ chillily
4楼-- · 2019-06-16 13:37

Even i was looking for solution to get project Name based on the document or file Name. I found it by using dte object. Initialized the dte object like below.

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

Then used following code to get the project name.

var projectItem = objDTE.Solution.FindProjectItem(document);
var projectUniqueName = projectItem.ContainingProject.UniqueName;
查看更多
太酷不给撩
5楼-- · 2019-06-16 13:39

ProjectItem.FileNames is a collection that represents the full paths of the associated files

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

查看更多
登录 后发表回答