Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify deployment path for XML documentation output path

I'm using the Swashbuckle.AspNetCore package for my .NET Core web api project. I want to add XML comments support so I have to set Build => Output => XML documentation file to true in the application settings.

enter image description here

Unfortunately the autogenerated path is absolute

C:\Users\myUser\...\repository\solution\project\project.xml

So this only works on my machine. Is there a way to use placeholders? E.g.

{{pathToProject}}\project.xml

so it works while debugging locally and for the deployment?


2 Answers

There's an easy way to generate an XML documentation file at a relative path. Just set the DocumentationFile property to true:

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

This was documented in another StackOverflow answer here: https://stackoverflow.com/a/47118584/19112

You can then set your SwaggerGenOptions to consume your XML documentation like this:

// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);

As shown in the sample here: https://code-maze.com/swagger-ui-asp-net-core-web-api/#ExtendingDocumentation

like image 126
dthrasher Avatar answered Feb 09 '26 12:02

dthrasher


Click the Browse... button and select a folder under the project path, such as bin\debug.

Then check the XML documentation file. It will generate a relative path.

enter image description here

like image 31
AnonymousKKYY Avatar answered Feb 09 '26 11:02

AnonymousKKYY



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!