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:
PlatformServices.Default.Application.ApplicationBasePath - points to the project root pathDirectory.GetCurrentDirectory() - the samePath.GetFullPath(".") - the sameIHostingEnvironment.WebRootPath - the sameOutput 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:
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..
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With