Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get XML comments output file location for ASP Core

I've added Swashbucklepackage to my ASP Core project.

I'd like to configure Swagger to use auto-generated by VS xml comments.

The problem is that I can't find the way to get that location:

  1. PlatformServices.Default.Application.ApplicationBasePath - points to the project root path
  2. Directory.GetCurrentDirectory() - the same
  3. Path.GetFullPath(".") - the same
  4. IHostingEnvironment.WebRootPath - the same

Output folder configured in <project>.xproj by BaseIntermediateOutputPath option.

But I can't get this location in runtime.

var pathToDoc = "????";
options.OperationFilter(new Swashbuckle.SwaggerGen.XmlComments.ApplyXmlActionComments(pathToDoc));

Bad solutions I see:

  1. add configuration option to AppSettings.json
  2. Relative path from project path (as I'm configuring bin output path).

But I'd like to use this with Docker, CI, localhost, so I don't think this would be the best solution to use hard-coded solution..

like image 750
deeptowncitizen Avatar asked Apr 18 '16 10:04

deeptowncitizen


1 Answers

You can try the following function to get the XML File path

 private string GetXmlCommentsPath()
        {
            var app = PlatformServices.Default.Application;
            return System.IO.Path.Combine(app.ApplicationBasePath, System.IO.Path.ChangeExtension(app.ApplicationName, "xml"));
        }

The xml file has the same name as the app. I am currently using this code in my project and it works fine.

like image 60
Naveen B Avatar answered Nov 15 '22 06:11

Naveen B