简体   繁体   中英

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.

Is it possible ?

You should call WebApiConfig.Register from your Web API project in your help project:

  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:

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. 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. 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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