0

So basically I am building nuget packages in TeamCity via a .proj file that runs a "pack" target:

  <MSBuild 
    Projects="$(MSBuildProjectDirectory)\PROJNAME.csproj"
    Targets="Rebuild;pack"
    Properties="Configuration=$(Configuration);Version=$(BUILD_NUMBER)" />

With an artifact output of:

PROJNAME\bin\Release\PROJNAME.%build.number%.nupkg

This works nicely for basic consuming of the nuget package, however I am having trouble getting the documentation xml files to work.

I have looked inside the output nupkg and I see that the documentation xml is actually bundled and included in the package, however the problem is that when I finally restore nuget packages in my consuming project, the dll gets copied across as expected, however the documentation does not.

doc included in nuget package

I wondered if this is because of the TC generated .nuspec file, and if I may need to abandon teamcities nuspec and create my own, however I was hoping to avoid this, given it works nicely the way it is, and handles versioning etc.

Is there a simple way to include documentation xml when the package is restored?

Josh Mc
  • 9,911
  • 8
  • 53
  • 66
  • After more time searching, I found https://stackoverflow.com/questions/19136999/nuget-package-not-copying-xmldoc-file-along-with-dll-to-bin, this appears to be a similar problem also without a solution. – Josh Mc Feb 21 '18 at 03:47
  • And another: https://stackoverflow.com/questions/44288689/nuget-restore-package-with-xml-file-content-working-sample I am beginning to wonder if this is a bug that hasn't really been solved. – Josh Mc Feb 21 '18 at 04:10

1 Answers1

0

In the end i found it came down to 3 things, being:


  1. Ensure projects configuration is set to generate documentation.

    • Either by adding code manually such as:

      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"><DocumentationFile>bin\$(Configuration)\netstandard2.0\Project.documentation.xml</DocumentationFile> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <DocumentationFile>bin\$(Configuration)\netstandard2.0\Project.documentation.xml</DocumentationFile> </PropertyGroup>

    • Or alternatively via the Visual Studio Project properties menu, if you are doing it through VS also make sure you do it for all configurations (as depicted as A in the picture below): Visual Studio project properties enable documentation generation


  1. Add EnableDocumentationFile to your .csproj file, eg:

    <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <RootNamespace>project</RootNamespace> <Configurations>Debug;Release</Configurations> <EnableDocumentationFile>true</EnableDocumentationFile> </PropertyGroup>


  1. and most importantly let your project know (again in your .csproj) that it should be copying over the documentation file, and use PackageFlatten if you want it to appear at the same level as your package dll:

    <ItemGroup> <None Remove="bin\$(Configuration)\netstandard2.0\Project.documentation.xml" /> </ItemGroup> <ItemGroup> <Content Include="bin\$(Configuration)\netstandard2.0\Project.documentation.xml"> <Pack>true</Pack> <PackageCopyToOutput>true</PackageCopyToOutput> <PackageFlatten>true</PackageFlatten> </Content> </ItemGroup>

Josh Mc
  • 9,911
  • 8
  • 53
  • 66