question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

3rd party XML documentation files in NuGet packages are not copied to my project's build folder

See original GitHub issue

I’ve dug around for a solution to this problem, but I only find issues related to dotnet publish not including a project’s xml documentation. My issue is that XML documentation files in NuGet packages are not copied to my project’s build folder. I hope the distinction is clear to a human (google couldn’t get it).

Steps to reproduce

Add some_other_library nuget package which includes xml documentation to you project. Do dotnet build

Expected behavior

The some_other_library.xml is included in the build (output) folder like so: image (screenshot from output of VS 2017)

Actual behavior

some_other_library.xml file is not present in the build (output) folder: image (screenshot of output of dotnet cli)

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.101)

Product Information:
 Version:            2.1.101
 Commit SHA-1 hash:  6c22303bf0

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.101\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.6
  Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:16
  • Comments:27 (2 by maintainers)

github_iconTop GitHub Comments

25reactions
Barsonaxcommented, May 31, 2020

@JoFrMueller you can do this to copy the xml and/or pdb files to the build output if it exists:

  <Target Name="CopyReferenceFiles" BeforeTargets="Build">
    <ItemGroup>
      <ReferenceFiles Include="%(Reference.RelativeDir)%(Reference.Filename).xml;%(Reference.RelativeDir)%(Reference.Filename).pdb" />
    </ItemGroup>
    
    <Message Text="Copying reference files to $(OutputPath)" Importance="High" />
    <Copy SourceFiles="@(ReferenceFiles)" DestinationFolder="$(OutputPath)" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
  </Target>

Also see my blog about this https://the-photographing-programmer.com/packagereferences-and-xml-documentation/

Granted it would be nice if there was build in support for this common use case but this seems to work pretty well and takes into account transitive dependencies as well and doesn’t lock your project into a specific targetframework.

We use this in our new project template for our game engine https://github.com/Barsonax/DualityProjectTemplate/blob/master/Source/Duality/Directory.Build.props#L12

18reactions
MonDevelopercommented, May 17, 2019

This limitation is really painfull when the xml documentation are the one describing the model packed with NuGET and used on the WebAPI contracts where something like swagger is used to self document the WebApi themselves, in such a case there’s no possibility to auto-describe the contracts (since it is autodiscovered using the xml documentations)

Read more comments on GitHub >

github_iconTop Results From Across the Web

XML documentation is in package but never copied to ...
Iam stuck in the same problem. I have my nuget package included in my project. My package contains the assembly and the .xml...
Read more >
Add NuGet package XML documentation to Swagger
Add API XML documentation from NuGet package to your Swagger definition! Copy XML docs from the nuget package to your build output.
Read more >
Create a package using the nuget.exe CLI
A detailed guide on designing and creating a NuGet package, including files and versioning.
Read more >
Building a NuGet Packages Architecture Part 6
Building a NuGet Packages Architecture Part 6/6: shows how to enhance your packages and the development experience.
Read more >
Managing Dependencies in .NET: .csproj, .packages.config ...
nuget.config is an XML file containing settings that control the behavior of NuGet. This file is not directly involved in dependency management ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found