Skip to content

[Bug] Source file based metadata generation use wrong version of .NET ref assemblies #9705

@filzrev

Description

@filzrev

Describe the bug
When explicitly specifying .NET SDK version by global.json with following settings.
Solution/Project build runs as expected with the specified SDK version.

But C# source file based builds always referencing the latest version of ref assemblies.
(e.g. C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\9.0.0-preview.1.24080.9)

Because ref assemblies directory is resolved by version name of Max().

var version = new DirectoryInfo(refDirectory).GetDirectories().Select(d => d.Name).Max();
var moniker = new DirectoryInfo(Path.Combine(refDirectory, version, "ref")).GetDirectories().Select(d => d.Name).Max();
var path = Path.Combine(refDirectory, version, "ref", moniker);

To Reproduce

  1. Use build environment that install .NET8/.NET9 SDKS.
  2. Create following global.json file at docfx root directory.
{
  "sdk": {
    "version": "8.0.200",
    "rollforward" : "disable"
  }
}
  1. Run docfx metadata command that targeting source file based build.
  2. Confirm following messages are displayed.

Using .NET Core SDK 8.0.200
Compiling C# files using .NET SDK 9.0.0-preview.1.24080.9 for net9.0

Expected behavior
Ref assemblies folder is resolved by using Environment.Version. (For temporary workaround)

It might be better to use TargetFramework version that is specified by docfx.json metadata properties.
https://dotnet.github.io/docfx/reference/docfx-json-reference.html#properties
And use NETStandard.Library.Ref DLLs when specified target to netstandard2.1.

Context (please complete the following information):

  • OS: Windows
  • Docfx version: [e.g. 2.75.3]

Additional context
This issue cause problems when adding support to reference external DLL features to
CreateCompilationFromCSharpFiles method.

Currently following version mismatch warnings are occurred.
When adding additional DLL that target .NET 8. And run docfx metadata commands

warning: warning CS1701: Assuming assembly reference 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'R3' matches identity 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.Runtime', you may need to supply runtime policy

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetGenerate .NET API reference docs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions