swagger-ui returns 500 after deployment

后端 未结 6 2187
夕颜
夕颜 2020-12-05 03:47

Out of the box configuration works perfectly on my machine, no problems at all.

But when I deploy to our test environment - I get the following message

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 04:25

    As stated in the accepted answer you have to make sure the XML documentation file output is in bin and not bin\Debug or bin\Release (verify this for all build configurations).

    I still got the 500 response because I use multiple XML documentation files. In my SwaggerConfig implementation I include XML documentation files from two projects (the WebApi project itself and a class library that is referenced by the WebApi project):

    c.IncludeXmlComments(string.Format(@"{0}\bin\MyWebApiProject.xml", System.AppDomain.CurrentDomain.BaseDirectory));
    c.IncludeXmlComments(string.Format(@"{0}\bin\ReferencedProject.xml", System.AppDomain.CurrentDomain.BaseDirectory));
    

    The XML documentation file of the WebApi project was published correctly to the bin folder of the site, however the XML documentation file of the referenced project was not (even though it appears in the bin folder of the compiled project).

    So you need to modify the WebApi project file (.csproj) in a text editor and add the following sections at the bottom (replace ReferencedProject):

    
      
        CustomCollectFiles;
        $(CopyAllFilesToSingleFolderForPackageDependsOn);
      
      
        CustomCollectFiles;
        $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
      
    
    
      
        <_CustomFiles Include="..\ReferencedProject\bin\ReferencedProject.xml" />
        
          bin\%(Filename)%(Extension)
        
      
    
    

    See How do you include additional files using VS2010 web deployment packages? for a full explanation.

提交回复
热议问题