dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
4k stars 851 forks source link

How to get Extension Methods to display when using assembly references #10117

Open UmaHarano opened 1 month ago

UmaHarano commented 1 month ago

Discussed in https://github.com/dotnet/docfx/discussions/10063

Originally posted by **UmaHarano** July 3, 2024 I am having issues with extension methods to be listed in the base class. I have two csproj files in my solution: * Project A with a "Map" class. * Project B in the same sln has a "MappingExtensions" class that defines extension methods for the Map class that is defined in Project A. ### Issue * If Project B has a "project reference" to Project A: Project A's Map class apiPage yml I generate using DocFX lists the extension methods defined in Project B. * If Project B has a assembly reference to Project A: Project A's Map class apiPage yml I generate using DocFX **_does not_** list the extension methods defined in Project B. This is the issue. The problem is my code base only uses "Assembly reference". So I am missing all the extension methods. Is there a solution or work around you can recommend? I cannot use project references.
filzrev commented 1 month ago

It seems be filtered out by following line. https://github.com/dotnet/docfx/blob/d0d5307d06edac3431e4e46073271f317357349a/src/Docfx.Dotnet/DotnetApiCatalog.ApiPage.cs#L439


Is there a solution or work around you can recommend? I cannot use project references.

As a temporary workaround. Is is able to use conditional compilation for docfx metadata command?

docfx.json

"metadata": [
    {
      "properties": {
        "DocfxMetadataBuild": "true"
      }
  ],

ProjectB.csproj

  <ItemGroup Condition="'$(DocfxMetadataBuild)' == 'true'">
    <ProjectReference Include="..\ClassLibrary1\ProjectA.csproj" />
  </ItemGroup>

  <ItemGroup Condition="'$(DocfxMetadataBuild)' != 'true'">
    <Reference Include="ProjectA">
      <HintPath>..\ClassLibrary1\bin\Release\net8.0\ProjectA.dll</HintPath>
    </Reference>
  </ItemGroup>
UmaHarano commented 1 month ago

@filzrev Thanks for the work around. The main reason this won't work is because I am building a documentation site for 17+ dlls. It would be a maintenance issue to evaluate the extensions in them in order to add these compilation conditions.

Any chance this can be fixed in the next round of DocFX updates?

image

filzrev commented 1 month ago

When using Assembly Reference. It seems ReduceExtensionMethod returns null at following lines. https://github.com/dotnet/docfx/blob/4d74101b977c0d13b5825c81414a059900eecfa3/src/Docfx.Dotnet/DotnetApiCatalog.ApiPage.cs#L439

Any chance this can be fixed in the next round of DocFX updates?

ReduceExtensionMethod is implemented by Roslyn API. So It would be difficult to fix on the docfx side.

I've found similar issue at Roslyn repository. But it seems not be resolved. https://github.com/dotnet/roslyn/issues/11950

UmaHarano commented 3 weeks ago

Thank you @filzrev for this info.