XML comments file could not be found - Swagger

前端 未结 8 793
慢半拍i
慢半拍i 2021-01-04 03:10

This is certainly one of those that drives you nuts. As the title indicates all I\'m simply trying to do is display comments pulled from an xml file using swagger.

I

相关标签:
8条回答
  • 2021-01-04 04:09

    These are the steps I needed in .Net Core 2.2:

    Put this in Startup.cs:

        public void ConfigureServices(IServiceCollection services)
        {
    
            ...
    
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
                {
                    ...
    
                    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                    c.IncludeXmlComments(xmlPath);
                });
        }
    

    Edit your .csproj file and add / change these nodes:

      <PropertyGroup>
        ...
        <!-- 
        Make sure documentation XML is also included when publishing (not only when testing)
        see https://github.com/Azure/service-fabric-issues/issues/190
        -->
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
      </PropertyGroup>
    
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        ...
        <DocumentationFile>bin\$(Configuration)\YOUR_PROJECT_NAME.xml</DocumentationFile>
      </PropertyGroup>
    
    0 讨论(0)
  • 2021-01-04 04:09

    May be I am little late but would like to share my fixes, I opened the .csproj file in Notepad++ and removed all the comments (), saved the file and opened the solution again, a (if your solution has more then one projects, do with all .csproj files)

    0 讨论(0)
提交回复
热议问题