Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3rd party library docs not resolved when running in Docker #15

Closed
jskeet opened this issue Feb 21, 2024 · 6 comments
Closed

3rd party library docs not resolved when running in Docker #15

jskeet opened this issue Feb 21, 2024 · 6 comments

Comments

@jskeet
Copy link

jskeet commented Feb 21, 2024

Context: NodaTime and NodaTime.Serialization libraries
.NET SDK: 8.0

I've managed to get the main NodaTime build to work with InheritDoc across all its target frameworks (netstandard2.0, net6.0, net8.0) but I'm struggling with NodaTime.Serialization libraries, e.g. NodaTime.Serialization.SystemTextJson which targets netstandard2.0 and netcoreapp3.1.
(I'm aware that netcoreapp3.1 is out of support; updating that target is a separate matter...)

I've reproduced the issue with the code below (inline and in a zip file). It's just a class library targeting netstandard2.0, with an abstract class derived from System.Text.Json.Serialization.JsonConverter<>. On my Windows box this builds correctly:

InheritDocTask replaced 1 of 1 inheritdoc tags and removed 0 non-public member docs in [...]\InheritDocDemo\bin\Release\netstandard2.0\InheritDocDemo.xml

When I run docker build --progress=plain . I get the following warning (I've wrapped it for readability):

obj/Release/netstandard2.0/InheritDocDemo.xml(10,10): InheritDocTask
warning IDT002: No matching documentation could be found for: M:InheritDocDemo.LibraryClass.CanConvert(System.Type),
which attempts to inherit from: M:System.Text.Json.Serialization.JsonConverter`1.CanConvert(System.Type) [/source/InheritDocDemo.csproj]

Using a target framework of net8.0, the build works fine in both Windows and Docker. For the main NodaTime build, it made sense that I needed to add extra SDKs in order to get appropriate XML files for the BCL - but in this case the only thing we're inheriting is the System.Text.Json library, which presumably comes with its own XML files. (If it would help to rewrite this example using Newtonsoft.Json, I could do that - it has the same issue.)

Files:

LibraryClass.cs:

using System;
using System.Text.Json.Serialization;

namespace InheritDocDemo;

/// <summary>Summary text</summary>
public abstract class LibraryClass : JsonConverter<string>
{
    /// <inheritdoc />
    public override bool CanConvert(Type type) => false;
}

InheritDocDemo.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <InheritDocEnabled>true</InheritDocEnabled>
    <LangVersion>latest</LangVersion>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <InheritDocEnabled>true</InheritDocEnabled>    
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="System.Text.Json" Version="6.0.9" />
    <PackageReference Include="SauceControl.InheritDoc" Version="2.0.1" PrivateAssets="all" />
  </ItemGroup>
</Project>

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /source
COPY Dockerfile *.csproj *.cs .
RUN dotnet build -c Release

InheritDocDemo.zip

@jskeet
Copy link
Author

jskeet commented Feb 21, 2024

Running with -v detailed on the dotnet build, I see this in the Windows build:

External ref docs found: 1

but in the Docker build:

External ref docs found: 0

... even though it looks like they're looking at the same set of files (131 in each), and both including .nuget/packages/system.text.json/6.0.9/lib/netstandard2.0/System.Text.Json.xml.

@jskeet
Copy link
Author

jskeet commented Feb 21, 2024

Running Ubuntu 20.04 via WSL, with only .NET 8.0 and .NET 6.0 SDKs installed, I don't see a problem.
Changing the Dockerfile to use .NET SDK 6.0 instead doesn't help.

I don't understand what's different under Docker...

@saucecontrol
Copy link
Owner

saucecontrol commented Feb 21, 2024

... even though it looks like they're looking at the same set of files (131 in each), and both including .nuget/packages/system.text.json/6.0.9/lib/netstandard2.0/System.Text.Json.xml.

It's looking for the doc file there, but the file isn't actually in the image, which is a silent error (perhaps I should be logging those in verbose mode).

Looks like the .NET SDK container images have the NuGet client set to not extract the XML files, as described in https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-environment-variables

I was able to get your sample to process correctly by adding the following to the dockerfile

ENV NUGET_XMLDOC_MODE=

Edit: Found the source of that setting.

https://github.com/dotnet/dotnet-docker/blob/6db5b3fb97961df982b7fffce4acbd94ed629306/src/sdk/8.0/bookworm-slim/amd64/Dockerfile#L14

Rationale is given in dotnet/dotnet-docker#2790

@jskeet
Copy link
Author

jskeet commented Feb 21, 2024

Will give that a try tomorrow - thank you so much for the quick response!

@saucecontrol saucecontrol changed the title Problems resolving documentation for a netstandard2.0 build using a 3rd party library 3rd party library docs not resolved when running in Docker Feb 22, 2024
@saucecontrol
Copy link
Owner

Happy to help! I reckon this surprising behavior warrants a readme note.

@jskeet
Copy link
Author

jskeet commented Feb 22, 2024

Happy to help! I reckon this surprising behavior warrants a readme note.

And I see you've already done so :) Will close this issue - again, thanks so much.

@jskeet jskeet closed this as completed Feb 22, 2024
jskeet added a commit to jskeet/nodatime.org that referenced this issue Feb 22, 2024
jskeet added a commit to nodatime/nodatime.org that referenced this issue Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants