Skip to content

[Feature Request] Support building with preview versions of the .NET SDK #9745

@martincostello

Description

@martincostello

Is your feature request related to a problem? Please describe.

Testing applications out with the .NET 9 Preview 1 SDK, it's not possible to build sites using docfx that have a net9.0 target framework.

This appears to be due to the code below, which requires that the SDK used is the same version as the runtime version docfx uses.

private static IEnumerable<MetadataReference> GetDefaultMetadataReferences(string language)
{
try
{
// Get current .NET runtime version with `{major}.{minor}` format.
var dotnetMajorMinorVersion = Environment.Version.ToString(2);
// Resolve .NET SDK packs directory path. (e.g. `C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.2\ref\net8.0`)
var dotnetExeDirectory = DotNetCorePathFinder.FindDotNetExeDirectory();
var refDirectory = Path.Combine(dotnetExeDirectory, "packs/Microsoft.NETCore.App.Ref");
var version = new DirectoryInfo(refDirectory).GetDirectories().Select(d => d.Name).Where(x => x.StartsWith(dotnetMajorMinorVersion)).Max()!;
var moniker = new DirectoryInfo(Path.Combine(refDirectory, version, "ref")).GetDirectories().Select(d => d.Name).Where(x => x.EndsWith(dotnetMajorMinorVersion)).Max()!;
var path = Path.Combine(refDirectory, version, "ref", moniker);
Logger.LogInfo($"Compiling {language} files using .NET SDK {version} for {moniker}");
Logger.LogVerbose($"Using SDK reference assemblies in {path}");
return Directory.EnumerateFiles(path, "*.dll", SearchOption.TopDirectoryOnly)
.Select(CreateMetadataReference);
}
catch (Exception ex)
{
Logger.LogVerbose(ex.ToString());
throw new DocfxException("Cannot find .NET Core SDK to compile the project.");
}
}

Even if the .NET 8 SDK is installed, in addition to .NET 9's, and DOTNET_ROLLFORWARD=Major is set, docfx will still and try to use the .NET 8 SDK to build for .NET 9, which fails.

Using .NET Core SDK 8.0.200
Loading project 
/runner/_work/MyProject/MyProject/src/MyProject/MyProject.csproj
  Determining projects to restore...
Error: /usr/share/dotnet/sdk/8.0.200/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(166,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 9.0.  Either target .NET 8.0 or lower, or use a version of the .NET SDK that supports .NET 9.0. Download the .NET SDK from https://aka.ms/dotnet/download [/runner/_work/MyProject/MyProject/src/MyProject/MyProject.csproj::TargetFramework=net9.0]

Describe the solution you'd like

docfx allows the use of newer .NET SDKs if installed in the execution environment.

Describe alternatives you've considered

Wait until November until .NET 9 is released and ignore my failing documentation builds.

Additional context

None.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fundamentalEngineering system and core components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions