简体   繁体   English

单独项目下的ASP.NET Web API帮助页面

[英]ASP.NET Web API Help page under separate project

I have ASP.NET Web API project and I want to add a Help page, but I want it to be in a separate project. 我有ASP.NET Web API项目,我想添加一个帮助页面,但我希望它在一个单独的项目中。

Is it possible ? 可能吗 ?

You should call WebApiConfig.Register from your Web API project in your help project: 您应该从帮助项目中的Web API项目调用WebApiConfig.Register:

  protected void Application_Start()
  {
     AreaRegistration.RegisterAllAreas();
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     GlobalConfiguration.Configure(MyApiProjectNamespace.WebApiConfig.Register);
  }

You can re-write XmlDocumentationProvider constructor to something like that: 您可以将XmlDocumentationProvider构造函数重写为以下内容:

public XmlDocumentationProvider(string appDataPath)
{
    if (appDataPath == null)
    {
        throw new ArgumentNullException(nameof(appDataPath));
    }

    var files = new[] { "MyWebApiProject.xml" /*, ... any other projects */ };
    foreach (var file in files)
    {
        var xpath = new XPathDocument(Path.Combine(appDataPath, file));
        _documentNavigators.Add(xpath.CreateNavigator());
    }
}

It will include all the xml documentation files that you list in the array. 它将包括您在数组中列出的所有xml文档文件。 You should also make sure your target Web API project (and all the model projects if needed) generates documentation on build and copies it to the right location. 您还应确保目标Web API项目(以及所有模型项目,如果需要)生成有关构建的文档并将其复制到正确的位置。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM