1

The generated package indeed includes the XML file next to the DLL file, however, when using the package from another project, the documentation is never copied to output directory.

Here are the relevant bits on how the package is generated:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
    ...
</PropertyGroup>

Tried the suggested answers in the following questions but without success:

Also tried to clear the packages cache and restarting Visual Studio but that didn't have any effect.

Question:

How does one get the XML documentation to be copied to output directory for a .NET 6 package?

aybe
  • 15,516
  • 9
  • 57
  • 105
  • Are you building for release or something like that which might omit the XML? – Joe_DM Nov 08 '22 at 02:06
  • No, currently I'm building under Debug configuration for the purpose of testing. – aybe Nov 08 '22 at 02:08
  • I ran a quick test of my own and like you, I don't see where the output is stored when setting `GenerateDocumentationFile` to true. I do however get an output when I use `DocumentationFile` and manually set the path. See https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/output#documentationfile Edit: I deleted the `DocumentationFile` and tested again with just `GenerateDocumentationFile` and I do indeed see the XML generated in my output folder. If you continue to get issues using both then maybe the issue is unrelated? – Joe_DM Nov 08 '22 at 02:15
  • Another quick question. The XML Documentation file you are expecting, is that on the top level Exe or WinExe project, or is it in some kind of class Library? If it's in a class Library, are you doing a rebuild of the main executable or are you building the library on it's own? I just tested with documentation in a referenced assembly and it seems to generate the XML okay when I build the parent executable project but building the library on it's own might not prompt it to generate the XML again. Just a thought. – Joe_DM Nov 08 '22 at 02:26
  • sorry about the spam.https://stackoverflow.com/questions/64044785/include-the-xml-documentation-from-a-nuget-package I notice this link you shared is more about copying the generated XML into a package when you create a NuGet. In this case it's a question more about copying files from your output directory into the package and not so much to do with generating the XML in the first place. – Joe_DM Nov 08 '22 at 02:30
  • You know what, something really interesting just happened, I tried with `DocumentationFile` and that didn't copy anything; then I checked in the consumer project whether IntelliSense shows up anything and it does actually! Then I tried removing `DocumentationFile` and regenerate the package, the documentation still shows up in consumer project. It appears that somehow, Visual Studio is able to fetch the documentation directly from `C:\users\username\.nuget\...` – aybe Nov 08 '22 at 02:31
  • I wonder if there would be an easy way to automatically find the location and copy it. I'm a bit confused what your source and target is, but if you need the documentation coming into your project or build then maybe something here can help automate the process? https://learn.microsoft.com/en-us/visualstudio/msbuild/copy-task?view=vs-2022 e.g. copy from packages to output, or something like that? – Joe_DM Nov 08 '22 at 02:34
  • Actually I'm generating a class library, I tried rebuilding one or the other as you suggested but that didn't change anything unfortunately. – aybe Nov 08 '22 at 02:35
  • I just made the following test, create new project with a class library with docs, reference generated package from a new console application; not even building the console application shows up documentation. Building the console application results in the same, no XML in output directory. Ultimately, if the behavior has changed and the documentation still shows up, I'm okay with that as long as it works. – aybe Nov 08 '22 at 02:42
  • Just one last comment before I part ways as I'm learning a bit here too as I go. I couldn't help but notice that there is no packages folder in the solution directory. As such I went searching for what environment variable you might be able to use to copy a file from a package into your output and I stumbled on this when setting build output to diagnostic. `AssetsFilePackageFolder` for this it points to my packages folder and so maybe you could use that if you need to copy a NuGet file to output dir. – Joe_DM Nov 08 '22 at 02:45
  • 1
    Thank you, I will check that one out. In the mean time, I leave the question open so maybe someone can shed some light on this. – aybe Nov 08 '22 at 02:47
  • I'm facing the exact same issue. XML file is part of the package, but it won't get copied to the consumer's bin directory along with the package's dll. Have you found anything yet? – Good Night Nerd Pride Dec 05 '22 at 16:18
  • Looks like XML docs now need an explicit copy-to-output: https://stackoverflow.com/questions/66696015/documentation-disappears-in-nuget-package – Good Night Nerd Pride Dec 05 '22 at 16:22
  • As mentioned before, turns out that it's not really a problem in the end. – aybe Dec 05 '22 at 23:58
  • 1
    @aybe did you managed to solve your problem. Iam stuck in the same problem. I have my nuget package included in my project. My package contains the assembly and the .xml doc file as well. But only my assembly (dll) is copied to the actual output Dir. I run though the comments here but it seems that nothing of it solved the actual problem. Any suggestions from your side? – A7GPS0 Jul 07 '23 at 19:53
  • Nope, haven't been able to. – aybe Jul 08 '23 at 01:41

0 Answers0