Search code examples
c#swaggernuget

XML Documentation not showing in swagger from Nuget package


I have a nuget package that is a library proj of common model objects. The nuget package was built with <GenerateDocumentationFile>true</GenerateDocumentationFile> , and I can see in the downloaded nuget package that the xml file is present. I see 0.0.61\lib\net6.0\ MyModels.dll and MyModels.xml

The issue I'm having is in my api project that consumes this nuget package, it seems the package's xml isn't getting copied to the output dir. Swagger isn't picking up the xml comments from it. I can see in the api projects bin directory the nuget package's xml file is missing.

I cleared nuget caches and forced restore on all nuget packages. Any advice?


Solution

  • askeli commented this link which led me to the answer https://stackoverflow.com/a/64006774/1729859

    I put this in my csproj file for locally running.

    <Target Name="_ResolveCopyLocalNuGetPkgXmls" AfterTargets="ResolveReferences">
        <ItemGroup>
          <ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->'%(RootDir)%(Directory)%(Filename).xml')" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)'!='' and Exists('%(RootDir)%(Directory)%(Filename).xml')" />
        </ItemGroup>
    </Target>
    

    That doesn't help with Docker though. I ended up putting this near the top of my docker file then rebuilding my images and it worked.

    ENV NUGET_XMLDOC_MODE=all