0

I've been asked to develop an addin that goes through a C# solution and extracts all the documentation from the source files and export them to an HTML file. We can't use normal document generators since the export needs to be in a specific format.

I know how to create a basic addin but have no clue as to how to go about enumerating through the source files.

Any ideas/resources on how to go about starting this project?

Thanks.

Tal Even-Tov
  • 153
  • 2
  • 11

1 Answers1

0

Here is some code I'm using to search for a file that ends with a given string.

The structure is like the Solution Explorer in Visual Studio:

Solution -> ProjectItems -> (Nested ProjectItems) -> FileNames

Wherever your code is executing, you can pull up the Projects in the Solution, and then the ProjectItems in those Projects.

var typeFileName = @"\MyClassName.cs";

// Search each Project in the Solution, exclude Unit Test Projects
foreach (Project item in _applicationObject.Solution.Projects.OfType<Project>().Where(p => !p.Name.EndsWith(".Tests")))
{
    // Search each ProjectItem recursively
    foreach (ProjectItem projectItem in item.ProjectItems)
    {
        RecursiveProjectItemSearch(projectItem, typeFileName);
    }
}

asdasd

private void RecursiveProjectItemSearch(ProjectItem projectItem, string typeFileName)
{
    for (short i = 0; i < projectItem.FileCount; i++)
    {
        var fileName = projectItem.FileNames[i];

        if (fileName.EndsWith(typeFileName))
        {
            // In my case, I want to open the file that I'm searching for
            _applicationObject.ItemOperations.OpenFile(fileName);
        }

        foreach(ProjectItem childProjectItem in projectItem.ProjectItems)
        {
            RecursiveProjectItemSearch(childProjectItem, typeFileName);
        }
    }
}

I don't know if this is the most optimal way to do this, but it should work. Given the code above you can change it to do a File.Open() and read the contents or something similar.

John B
  • 20,062
  • 35
  • 120
  • 170