首页 > 解决方案 > 如何使用docfx从解决方案中的项目中收集所有xml文档?

问题描述

我有这样的解决方案结构:

Solution
--Project.DAL
------bin
------obj
------Project.DAL.csproj
--Project.BLL
------bin
------obj
------Project.BLL.csproj
--Project.View
------bin
------obj
------Project.View.csproj
--Project.Documentaion
------_site
------another-files-of-docfx

我尝试更改 docfx.json 的道具和值

    {
      "src": [
        {
          "files": [
            "Project.DAL.csproj",
            "Project.BLL.csproj",
            "Project.View.csproj"
          ],
          "src": "Project"
        }
      ],
      "dest": "api",
      "disableGitFeatures": false,
      "disableDefaultFilter": false
    }

每个项目都有 nugetpackage docfx.console。构建解决方案后,我在每个项目中都有文档。我想将解决方案中项目的所有 xml 文档收集到文件夹 Project.Documentation。请告诉我,这可能与否?如果是,你能帮助我并告诉我我做错了什么以及在哪里做错了吗?

标签: c#xml.net-coredocfx

解决方案


看看以下是否有效。我可以使用 xml linq 而不是使用正则表达式。:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string mainProject = @"c:\temp\myProject.csproj";
            string projectName = mainProject.Substring(mainProject.LastIndexOf("\\") + 1);
            string folder = mainProject.Substring(0, mainProject.LastIndexOf("\\") + 1);
            GetProjectsRecursive(folder, projectName, 0);
            Console.ReadLine();
        }
        static void GetProjectsRecursive(string folder, string project, int level)
        {
            string pattern = "<ProjectReference Include=\"(?'project'[^\"]+)";

            if (File.Exists(folder + project))
            {
                string contents = File.ReadAllText(folder + project);
                MatchCollection matches = Regex.Matches(contents, pattern, RegexOptions.Multiline);
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        string projectName = match.Groups["project"].Value;
                        string childProjectName = projectName.Substring(projectName.LastIndexOf("\\") + 1);
                        string childFolder = projectName.Substring(0, projectName.LastIndexOf("\\") + 1);
                        Console.WriteLine("{0}Project : '{1}', Refeference Project : '{2}'", new string(' ', level), project, projectName);

                        if (childFolder.StartsWith("..\\"))
                        {
                            childFolder = folder + childFolder;
                        }
                        GetProjectsRecursive(childFolder, childProjectName, level + 1);
                    }
                }
            }
            else
            {
                Console.WriteLine("Project Does Not Exist : '{0}'", folder + project);
            }
        }
    }
}

推荐阅读