12

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 ?

Andrei
  • 42,814
  • 35
  • 154
  • 218
koryakinp
  • 3,989
  • 6
  • 26
  • 56
  • Of course you can, help pages work on XML documentation to which you provide the path. But one project generally is one web application. Do you want the help page on a different port during development and in a different application on IIS? Can you explain a bit more about your exact goal? – CodeCaster Feb 04 '15 at 09:33
  • I do not want to mess my Web API project with all the resources which is necessary for the Help page, that is the main reason I want my code for Help page to be in a separate project. – koryakinp Feb 04 '15 at 09:42
  • The help page is created in its own area. If you stick with the area and put the resources into that area your project shouldn't be messed up. – Horizon_Net Feb 04 '15 at 10:05
  • I always put my ApiControllers in a seperate DLL project. As routing can still find the controllers there, I'm pretty sure the ApiExplorer will be able to find them there too. – Darrel Miller Feb 06 '15 at 02:44
  • 7
    To the people voting to close this question, please don't. This is a very valid question and one more people should understand how to achieve. – Darrel Miller Feb 06 '15 at 02:46
  • Did you find a solution? – Leandro Bardelli Mar 03 '16 at 16:47
  • 1
    [This](http://stackoverflow.com/a/21895258/2501279) seems to be about the same issue, if i'm correct. – Guru Stron Apr 17 '16 at 08:55
  • 1
    Possible duplicate of [How can Xml Documentation for Web Api include documentation from beyond the main project?](http://stackoverflow.com/questions/21895257/how-can-xml-documentation-for-web-api-include-documentation-from-beyond-the-main) – BMac Apr 21 '16 at 15:26

2 Answers2

1

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. enter image description here

Andrei
  • 42,814
  • 35
  • 154
  • 218
1

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);
  }