asp.net-core-webapiswagger-ui.net-5webapixml-comments

Can not found file Xml comment in Web API(.NET 5 web API)


This is a picture of the code config file path of XML comment file. enter image description here

When I deploy in Azure, I have a problem that It can't find this XML file enter image description here


Solution

  • XML comments can be enabled with the following approaches:

    Right-click the project in Solution Explorer and select Edit <project_name>.csproj. Manually add the highlighted lines to the .csproj file:

    <PropertyGroup>
      <GenerateDocumentationFile>true</GenerateDocumentationFile>
      <NoWarn>$(NoWarn);1591</NoWarn>
    </PropertyGroup>
    
    
    
    
    
    public void ConfigureServices(IServiceCollection services)
        {
             .......//swagger config..
         var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
    

    Then you can read the xml: enter image description here