Skip to content

Commit

Permalink
feat: Add .NET 9 support (and drop .NET 6 support) (#10239)
Browse files Browse the repository at this point in the history
* feat: add .NET 9 support (And drop .NET 6 support)

* chore: temporary disable package validation

* chore: remove ifdefs that is not used after .NET 6 support dropped

---------

Co-authored-by: Yufei Huang <[email protected]>
  • Loading branch information
filzrev and yufeih authored Oct 20, 2024
1 parent 51ac3f9 commit 89c5705
Show file tree
Hide file tree
Showing 32 changed files with 31 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ runs:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.x
9.x
8.x
- run: npm install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
- run: dotnet test -c Release -f net8.0 --no-build --collect:"XPlat Code Coverage" --consoleLoggerParameters:"Summary;Verbosity=Minimal"
id: test-net80

- run: dotnet test -c Release -f net6.0 --no-build --collect:"XPlat Code Coverage" --consoleLoggerParameters:"Summary;Verbosity=Minimal"
- run: dotnet test -c Release -f net9.0 --no-build --collect:"XPlat Code Coverage" --consoleLoggerParameters:"Summary;Verbosity=Minimal"
if: matrix.os == 'ubuntu-latest'
id: test-net60
id: test-net90

- run: npm i -g @percy/cli
if: matrix.os == 'ubuntu-latest'
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ jobs:
permissions:
packages: write
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.x
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks Condition="'$(DOCFX_PREVIEW_BUILD)' == 'true'">net8.0;net9.0</TargetFrameworks>
<LangVersion>Preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
16 changes: 1 addition & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,7 @@
<PackageVersion Include="YamlDotNet" Version="15.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<!-- "17.3.2" is the latest compatible version for .NET 6 -->
<PackageVersion Include="Microsoft.Build" Version="[17.3.2]" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.7.8" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="[4.8.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="[4.8.0]" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'">
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dotnet-api-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ If your project targets multiple target frameworks, docfx internally builds each
}],
"dest": "api",
"properties": {
"TargetFramework": "net6.0"
"TargetFramework": "net8.0"
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In this section we will build a simple documentation site on your local machine.

> Prerequisites
> - Familiarity with the command line
> - Install [.NET SDK](https://dotnet.microsoft.com/en-us/download) 6.0 or higher
> - Install [.NET SDK](https://dotnet.microsoft.com/en-us/download) 8.0 or higher
> - Install [Node.js](https://nodejs.org/) v20 or higher
Make sure you have [.NET SDK](https://dotnet.microsoft.com/en-us/download) installed, then open a terminal and enter the following command to install the latest docfx:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Goal and limitation

Preparation
-----------
1. Create a new C# class library targeting `net6.0` or later.
1. Create a new C# class library targeting `net8.0` or later.

2. Add NuGet package reference to `System.Composition`, `Docfx.Plugins` and `Docfx.Common`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion samples/seed/dotnet/solution/CatLibrary/CatLibrary.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Docfx.App/Docfx.App.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>2.70.0</PackageValidationBaselineVersion>
<!-- TODO: Enable package validation after v2.78.0 packages are published -->
<EnablePackageValidation>false</EnablePackageValidation>
<PackageValidationBaselineVersion>2.78.0</PackageValidationBaselineVersion>
<Description>Docfx published as a library for extensibility and advanced customization</Description>
</PropertyGroup>

Expand Down
6 changes: 0 additions & 6 deletions src/Docfx.Build/Conceptual/WordCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ namespace Docfx.Build.ConceptualDocuments;
internal static class WordCounter
{
private static readonly string[] ExcludeNodeXPaths = ["//title"];

#if NET8_0_OR_GREATER
private static readonly System.Buffers.SearchValues<char> SpecialChars = System.Buffers.SearchValues.Create(".?!;:,()[]");
#else
private static readonly string SpecialChars = ".?!;:,()[]";
#endif

private static readonly char[] DelimiterChars = [' ', '\t', '\n'];

public static long CountWord(string html)
Expand Down
6 changes: 1 addition & 5 deletions src/Docfx.Build/DocumentBuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,9 @@ public IImmutableList<string> GetTocFileKeySet(string key)

public void RegisterToc(string tocFileKey, string fileKey)
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(fileKey);
ArgumentException.ThrowIfNullOrEmpty(tocFileKey);
#else
if (string.IsNullOrEmpty(fileKey)) throw new ArgumentNullException(nameof(fileKey));
if (string.IsNullOrEmpty(tocFileKey)) throw new ArgumentNullException(nameof(tocFileKey));
#endif

TocMap.AddOrUpdate(
fileKey,
new HashSet<string>(FilePathComparer.OSPlatformSensitiveRelativePathComparer) { tocFileKey },
Expand Down
7 changes: 0 additions & 7 deletions src/Docfx.Build/TableOfContents/TocHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ internal static List<FileModel> ResolveToc(ImmutableList<FileModel> models)

public static TocItemViewModel LoadSingleToc(string file)
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(file);
#else
if (string.IsNullOrEmpty(file))
{
throw new ArgumentNullException(nameof(file));
}
#endif

if (!EnvironmentContext.FileAbstractLayer.Exists(file))
{
Expand Down
5 changes: 0 additions & 5 deletions src/Docfx.Build/TemplateProcessors/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ public void ProcessTheme(string outputDirectory, bool overwrite)

private bool TryExportResourceFiles(IEnumerable<string> resourceNames, string outputDirectory, bool overwrite, string? regexFilter = null)
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(outputDirectory);
#else
if (string.IsNullOrEmpty(outputDirectory))
throw new ArgumentNullException(nameof(outputDirectory));
#endif

if (!resourceNames.Any())
return false;
Expand Down
10 changes: 2 additions & 8 deletions src/Docfx.Build/TemplateProcessors/TemplateProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ public TemplateProcessor(ResourceFileReader resourceProvider, DocumentBuildConte

public TemplateBundle GetTemplateBundle(string documentType)
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(documentType);
#else
if (string.IsNullOrEmpty(documentType)) throw new ArgumentNullException(nameof(documentType));
#endif

return _templateCollection[documentType];
}

public bool TryGetFileExtension(string documentType, out string fileExtension)
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(documentType);
#else
if (string.IsNullOrEmpty(documentType)) throw new ArgumentNullException(nameof(documentType));
#endif

fileExtension = string.Empty;
if (_templateCollection.Count == 0) return false;
var templateBundle = _templateCollection[documentType];
Expand Down
7 changes: 0 additions & 7 deletions src/Docfx.Common/Path/RelativePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,7 @@ public string GetFileNameWithoutExtension()

public RelativePath ChangeFileName(string fileName)
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(fileName);
#else
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentNullException(nameof(fileName));
}
#endif

if (fileName.Contains('\\') || fileName.Contains('/') || fileName == ".." || fileName == ".")
{
Expand Down
5 changes: 0 additions & 5 deletions src/Docfx.Dotnet/Docfx.Dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
<ProjectReference Include="..\Docfx.Plugins\Docfx.Plugins.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Formats.Asn1" />
<PackageReference Include="HtmlAgilityPack" />
Expand Down
22 changes: 0 additions & 22 deletions src/Docfx.Dotnet/DotnetApiCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ internal static async Task Exec(MetadataJsonConfig config, DotnetApiOptions opti
{
var stopwatch = Stopwatch.StartNew();

EnsureMSBuildLocator();

try
{
string originalGlobalNamespaceId = VisitorHelper.GlobalNamespaceId;
Expand Down Expand Up @@ -116,26 +114,6 @@ void WriteYaml(string outputFolder, string id, Build.ApiPage.ApiPage apiPage)
}
}

private static void EnsureMSBuildLocator()
{
#if NET6_0
try
{
if (!Microsoft.Build.Locator.MSBuildLocator.IsRegistered)
{
var vs = Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults() ?? throw new Docfx.Exceptions.ExtractMetadataException(
$"Cannot find a supported .NET Core SDK. Install .NET Core SDK {Environment.Version.Major}.{Environment.Version.Minor}.x to build .NET API docs.");

Logger.LogInfo($"Using {vs.Name} {vs.Version}");
}
}
catch (Exception e)
{
throw new Docfx.Exceptions.ExtractMetadataException(e.Message, e);
}
#endif
}

private static ExtractMetadataConfig ConvertConfig(MetadataJsonItemConfig configModel, string configDirectory, string outputDirectory)
{
var projects = configModel.Src;
Expand Down
3 changes: 0 additions & 3 deletions src/Docfx.Dotnet/SymbolFormatter.Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,9 @@ private class PropertySymbol : IPropertySymbol
public string ToDisplayString(SymbolDisplayFormat format = null) => Inner.ToDisplayString(format);
public ImmutableArray<SymbolDisplayPart> ToMinimalDisplayParts(SemanticModel semanticModel, int position, SymbolDisplayFormat format = null) => Inner.ToMinimalDisplayParts(semanticModel, position, format);
public string ToMinimalDisplayString(SemanticModel semanticModel, int position, SymbolDisplayFormat format = null) => Inner.ToMinimalDisplayString(semanticModel, position, format);

#if NET8_0_OR_GREATER
public IPropertySymbol PartialDefinitionPart => Inner.PartialDefinitionPart;
public IPropertySymbol PartialImplementationPart => Inner.PartialImplementationPart;
public bool IsPartialDefinition => Inner.IsPartialDefinition;
#endif
}

public class MethodSymbol : IMethodSymbol
Expand Down
6 changes: 0 additions & 6 deletions src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ public MarkupResult Markup(string content, string filePath)
public MarkupResult Markup(string content, string filePath, bool multipleYamlHeader)
{
ArgumentNullException.ThrowIfNull(content);

#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(filePath);
#else
if (string.IsNullOrEmpty(filePath))
throw new ArgumentNullException(nameof(filePath));
#endif

var pipeline = CreateMarkdownPipeline(isInline: false, multipleYamlHeader);

Expand Down
2 changes: 1 addition & 1 deletion src/docfx/docfx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-->
<Target Name="RewriteDocfxTemplateFiles" AfterTargets="PackTool">
<PropertyGroup>
<!-- Select first element of TargetFrameworks as template source (e.g. `net6.0` is selected when TargetFrameworks `net6.0;net7.0;net8.0`) -->
<!-- Select first element of TargetFrameworks as template source (e.g. `net8.0` is selected when TargetFrameworks `net8.0;9.0`) -->
<DocfxTemplateSourceTargetFramework>$(TargetFrameworks.Split(";")[0])</DocfxTemplateSourceTargetFramework>
</PropertyGroup>
<!-- If TargetFramework is selected version. Rewrite template files PackagePath.-->
Expand Down
11 changes: 1 addition & 10 deletions test/Docfx.Dotnet.Tests/GenerateMetadataFromCSUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2580,12 +2580,7 @@ public void Undefined(ConsoleKey key = ConsoleKey.None) { }

var undefined = output.Items[0].Items[0].Items[1];
Assert.NotNull(undefined);

#if NET8_0_OR_GREATER
Assert.Equal("public void Undefined(ConsoleKey key = ConsoleKey.None)", undefined.Syntax.Content[SyntaxLanguage.CSharp]);
#else
Assert.Equal("public void Undefined(ConsoleKey key = default)", undefined.Syntax.Content[SyntaxLanguage.CSharp]);
#endif
}

[Fact]
Expand Down Expand Up @@ -2653,12 +2648,8 @@ public void EnumUndefinedValue(ConsoleKey? key = (ConsoleKey)999) { }

var enumUndefinedDefault = output.Items[0].Items[0].Items[3];
Assert.NotNull(enumUndefinedDefault);

#if NET8_0_OR_GREATER
Assert.Equal("public void EnumUndefinedDefault(ConsoleKey? key = ConsoleKey.None)", enumUndefinedDefault.Syntax.Content[SyntaxLanguage.CSharp]);
#else
Assert.Equal("public void EnumUndefinedDefault(ConsoleKey? key = null)", enumUndefinedDefault.Syntax.Content[SyntaxLanguage.CSharp]);
#endif

var enumUndefinedValue = output.Items[0].Items[0].Items[4];
Assert.NotNull(enumUndefinedValue);
Assert.Equal("public void EnumUndefinedValue(ConsoleKey? key = (ConsoleKey)999)", enumUndefinedValue.Syntax.Content[SyntaxLanguage.CSharp]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class CatException<T> : Exception, ISerializable
#### Inherited Members

[Exception.GetBaseException\(\)](https://learn.microsoft.com/dotnet/api/system.exception.getbaseexception),
[Exception.GetObjectData\(SerializationInfo, StreamingContext\)](https://learn.microsoft.com/dotnet/api/system.exception.getobjectdata),
[Exception.GetType\(\)](https://learn.microsoft.com/dotnet/api/system.exception.gettype),
[Exception.ToString\(\)](https://learn.microsoft.com/dotnet/api/system.exception.tostring),
[Exception.Data](https://learn.microsoft.com/dotnet/api/system.exception.data),
Expand Down
4 changes: 2 additions & 2 deletions test/docfx.Tests/Assets/multi-frameworks-test.csproj.sample.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions test/docfx.Tests/Assets/ref.csproj.sample.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions test/docfx.Tests/Assets/template/plugins/plugins.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down
Loading

0 comments on commit 89c5705

Please sign in to comment.