Frage

Given I have a file in a TFS source code repository. I'm trying to discover programatically which cs project this file belongs to and then which other projects\solutions rely on the output of that project.

How could I go about doing this?

War es hilfreich?

Lösung 2

The csproj files are Xml based files, so you can symply open the file, process the Xml and search for the file. For files, you can find if a file is included in the project by searching in them searching for the Tag ItemGroup and within ItemGroup the Tag Compile, if the file is for compilation, if not search within GroupItem the None or other according to the file nature

For searching for referenced projects you have to search in GroupItem Tags about ProjectReference Tag

There is other useful tags like Content for resources, None...etc.

I encourage you to open your csproj in notepad++ and see what you can find, it is pretty simple.

Andere Tipps

proj files are XML files, if you parse them you would find all the project files under ItemGroup. You might find multiple ItemGroup elements. Some has children of type Compile, Contents...etc So I would suggest that you check a couple of them to have an idea of what I am talking about. cs files will most likely be under Compile

For your project dependencies, I never did that before, but if the dependencies are declared in your solution, then in every project you should find a ProjectReference to the other projects it depends on.

In conclusion, you need to parse the project files XML then query for your source files and project dependencies.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top