ASP.NET Web API Help page under separate project
Asked Answered
D

2

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 ?

Durian answered 4/2, 2015 at 8:48 Comment(8)
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?Rana
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.Durian
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.Regalado
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.Sutphin
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.Sutphin
Did you find a solution?Indraft
This seems to be about the same issue, if i'm correct.Anhinga
Possible duplicate of How can Xml Documentation for Web Api include documentation from beyond the main project?Monsoon
S
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

Soccer answered 21/4, 2016 at 18:10 Comment(0)
T
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);
  }
Transmitter answered 26/12, 2016 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.