Click to See Complete Forum and Search --> : How to identify a certain file as belong to a certain solution?


Trinominal
May 14th, 2009, 04:42 PM
Hi,

I'm writing a VS2008 Add-In in C#.
When a solution is opened, I have the Solution object (from the DTE object).
Given a certain path to a file, I'm trying to distinguish whether or not this file belong to the solution or not.

I tried to solve this by iterating all the projects in the solution (by "solution.Project.GetEnumerator()"), and in each project iterate all the project items (by project.ProjectItems.GetEnumerator()"), and I am getting most of the files that belong to the solution, but for some reason, there are files which are not in the project items I'm iterating.

For example, if I have a form class, then the file "Form.cs" is one of the project items, but files like "Form.Designer.cs" and "Form.resx" are not found in the project items collection. Also files under the property directory, e.g. "AssemblyInfo.cs" are not found (only the "Properties" is found as a project item).

Can someone please:
1. Tell me whether is a better way to distinguish whether a certain file belong to a solution or not ?
2. Tell me why the files specified above are not listed in the project items collections ?

Thanks!

dglienna
May 14th, 2009, 06:54 PM
1) What are you using? If you know that a file exists of each type, and you have the folder, you could just browse the folder with a filter

2) Not sure

#3> Why? (mine for you)

cilu
May 15th, 2009, 07:50 AM
You should explain what exactly you are trying to do.

memeloo
May 15th, 2009, 09:16 AM
You should explain what exactly you are trying to do.

hmm, didn't he say that he's writing an add-in for visual studio and that this add-in should handle the file added event when a file has been added to a solution?

Trinominal
May 21st, 2009, 01:57 PM
Hi,

Sorry for the late reply.

I got the answers to my two questions here they are:

1) dte.Solution.FindProjectItem()
2) The specified items above appears, but not in the first level. They are childs of project items in the project. Need to iterate the project items, and for each project item which have childs, iterate them as well, recursively.

Regards