Skip to content

Build against .NET 10 preview #1710

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jobs:
dotnet-version: |
8.0.*
9.0.*
- name: Setup .NET 10 preview
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.*
dotnet-quality: 'preview'
- name: Show installed versions
shell: pwsh
run: |
Expand Down Expand Up @@ -166,6 +171,11 @@ jobs:
dotnet-version: |
8.0.*
9.0.*
- name: Setup .NET 10 preview
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.*
dotnet-quality: 'preview'
- name: Git checkout
uses: actions/checkout@v4
- name: Restore tools
Expand Down Expand Up @@ -221,6 +231,11 @@ jobs:
dotnet-version: |
8.0.*
9.0.*
- name: Setup .NET 10 preview
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.*
dotnet-quality: 'preview'
- name: Git checkout
uses: actions/checkout@v4
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
dotnet-version: |
8.0.*
9.0.*
- name: Setup .NET 10 preview
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.*
dotnet-quality: 'preview'
- name: Git checkout
uses: actions/checkout@v4
- name: Initialize CodeQL
Expand Down
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>

<PropertyGroup>
<!-- .NET 10 Preview -->
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<NoWarn>$(NoWarn);NU1903;NU5104;NU1608</NoWarn>
</PropertyGroup>

<PropertyGroup>
<!--
Disabled IDE analyzers for "Use collection expression" because they are dangerous in a subtle way.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

Expand Down
13 changes: 13 additions & 0 deletions package-versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
<XunitVisualStudioVersion>2.8.*</XunitVisualStudioVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net10.0'">
<!-- Published dependencies (only update on major version change) -->
<EntityFrameworkCoreFrozenVersion>10.0.*-*</EntityFrameworkCoreFrozenVersion>
<SwashbuckleFrozenVersion>9.0.0-pr.3283.*</SwashbuckleFrozenVersion>

<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<AspNetCoreVersion>10.0.*-*</AspNetCoreVersion>
<SwashbuckleVersion>9.0.0-pr.3283.*</SwashbuckleVersion>
<MicrosoftApiServerVersion>10.0.*-*</MicrosoftApiServerVersion>
<EntityFrameworkCoreVersion>10.0.*-*</EntityFrameworkCoreVersion>
<EntityFrameworkCorePomeloVersion>9.0.*-*</EntityFrameworkCorePomeloVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net9.0'">
<!-- Published dependencies (only update on major version change) -->
<EntityFrameworkCoreFrozenVersion>N/A</EntityFrameworkCoreFrozenVersion>
Expand Down
3 changes: 2 additions & 1 deletion src/Examples/DapperExample/DapperExample.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand All @@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EntityFrameworkCorePomeloVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/GettingStarted/GettingStarted.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0</TargetFrameworks>
<OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild>
<OpenApiDocumentsDirectory>GeneratedSwagger</OpenApiDocumentsDirectory>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
if (_httpContextAccessor.HttpContext == null)
{
swaggerDoc.Servers ??= new List<OpenApiServer>();

swaggerDoc.Servers.Add(new OpenApiServer
{
Url = "https://localhost:44340"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<!-- TargetFrameworks does not work, see https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2706 -->
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/ReportsExample/ReportsExample.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;netstandard1.0</TargetFrameworks>
<TargetFrameworks>net10.0;net8.0;netstandard1.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RootNamespace>JsonApiDotNetCore</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net10.0;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ public void Configure(SwaggerGenOptions options)
options.DocumentFilter<StringEnumOrderingFilter>();
options.DocumentFilter<SetSchemaTypeToObjectDocumentFilter>();
options.DocumentFilter<UnusedComponentSchemaCleaner>();
options.DocumentFilter<SortSchemasFilter>();
}

private List<Type> SelectDerivedTypes(Type baseType)
{
if (BaseToDerivedSchemaTypes.TryGetValue(baseType, out Type? schemaOpenType))
if (BaseToDerivedSchemaTypes.TryGetValue(baseType, out var schemaOpenType))
{
return GetConstructedTypesFromResourceGraph(schemaOpenType);
}
Expand All @@ -90,7 +91,7 @@ private List<Type> SelectDerivedTypes(Type baseType)

if (baseType.IsAssignableTo(typeof(IIdentifiable)))
{
ResourceType? resourceType = _resourceGraph.FindResourceType(baseType);
var resourceType = _resourceGraph.FindResourceType(baseType);

if (resourceType != null && resourceType.IsPartOfTypeHierarchy())
{
Expand All @@ -105,9 +106,9 @@ private List<Type> GetConstructedTypesFromResourceGraph(Type schemaOpenType)
{
List<Type> constructedTypes = [];

foreach (ResourceType resourceType in _resourceGraph.GetResourceTypes())
foreach (var resourceType in _resourceGraph.GetResourceTypes())
{
Type constructedType = schemaOpenType.MakeGenericType(resourceType.ClrType);
var constructedType = schemaOpenType.MakeGenericType(resourceType.ClrType);
constructedTypes.Add(constructedType);
}

Expand All @@ -118,7 +119,7 @@ private List<Type> GetConstructedTypesForAtomicOperation()
{
List<Type> derivedTypes = [];

foreach (ResourceType resourceType in _resourceGraph.GetResourceTypes())
foreach (var resourceType in _resourceGraph.GetResourceTypes())
{
derivedTypes.AddRange(AtomicOperationDerivedSchemaTypes.Select(openType => openType.MakeGenericType(resourceType.ClrType)));
}
Expand All @@ -135,7 +136,7 @@ private static List<Type> GetResourceDerivedTypes(ResourceType baseType)

private static void IncludeDerivedTypes(ResourceType baseType, List<Type> clrTypes)
{
foreach (ResourceType derivedType in baseType.DirectlyDerivedTypes)
foreach (var derivedType in baseType.DirectlyDerivedTypes)
{
clrTypes.Add(derivedType.ClrType);
IncludeDerivedTypes(derivedType, clrTypes);
Expand All @@ -144,8 +145,8 @@ private static void IncludeDerivedTypes(ResourceType baseType, List<Type> clrTyp

private static List<string> GetOpenApiOperationTags(ApiDescription description, IControllerResourceMapping controllerResourceMapping)
{
MethodInfo actionMethod = description.ActionDescriptor.GetActionMethod();
ResourceType? resourceType = controllerResourceMapping.GetResourceTypeForController(actionMethod.ReflectedType);
var actionMethod = description.ActionDescriptor.GetActionMethod();
var resourceType = controllerResourceMapping.GetResourceTypeForController(actionMethod.ReflectedType);

return resourceType == null ? ["operations"] : [resourceType.PublicName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ private static void IncludeResourceType(ResourceType resourceType, ISet<Resource

private static void IncludeDerivedTypes(ResourceType resourceType, ISet<ResourceType> resourceTypesFound)
{
foreach (ResourceType derivedType in resourceType.DirectlyDerivedTypes)
foreach (var derivedType in resourceType.DirectlyDerivedTypes)
{
IncludeResourceType(derivedType, resourceTypesFound);
}
}

private static void IncludeRelatedTypes(ResourceType resourceType, ISet<ResourceType> resourceTypesFound)
{
foreach (RelationshipAttribute relationship in resourceType.Relationships)
foreach (var relationship in resourceType.Relationships)
{
IncludeResourceType(relationship.RightType, resourceTypesFound);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public JsonApiActionDescriptorCollectionProvider(IActionDescriptorCollectionProv

private ActionDescriptorCollection GetActionDescriptors()
{
List<ActionDescriptor> newDescriptors = _defaultProvider.ActionDescriptors.Items.ToList();
ActionDescriptor[] endpoints = newDescriptors.Where(IsVisibleJsonApiEndpoint).ToArray();
var newDescriptors = _defaultProvider.ActionDescriptors.Items.ToList();
var endpoints = newDescriptors.Where(IsVisibleJsonApiEndpoint).ToArray();

foreach (ActionDescriptor endpoint in endpoints)
foreach (var endpoint in endpoints)
{
MethodInfo actionMethod = endpoint.GetActionMethod();
JsonApiEndpointMetadataContainer endpointMetadataContainer = _jsonApiEndpointMetadataProvider.Get(actionMethod);
var actionMethod = endpoint.GetActionMethod();
var endpointMetadataContainer = _jsonApiEndpointMetadataProvider.Get(actionMethod);

List<ActionDescriptor> replacementDescriptorsForEndpoint =
[
Expand All @@ -62,7 +62,7 @@ .. AddJsonApiMetadataToAction(endpoint, endpointMetadataContainer.ResponseMetada
}
}

int descriptorVersion = _defaultProvider.ActionDescriptors.Version;
var descriptorVersion = _defaultProvider.ActionDescriptors.Version;
return new ActionDescriptorCollection(newDescriptors.AsReadOnly(), descriptorVersion);
}

Expand Down Expand Up @@ -136,9 +136,9 @@ private static bool ProducesJsonApiResponseDocument(ActionDescriptor endpoint)

if (produces != null)
{
foreach (string contentType in produces.ContentTypes)
foreach (var contentType in produces.ContentTypes)
{
if (MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue? headerValue))
if (MediaTypeHeaderValue.TryParse(contentType, out var headerValue))
{
if (headerValue.MediaType.Equals(DefaultMediaType, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -156,14 +156,14 @@ private static List<ActionDescriptor> Expand(ActionDescriptor genericEndpoint, N
{
List<ActionDescriptor> expansion = [];

foreach ((string relationshipName, Type documentType) in metadata.DocumentTypesByRelationshipName)
foreach ((var relationshipName, var documentType) in metadata.DocumentTypesByRelationshipName)
{
if (genericEndpoint.AttributeRouteInfo == null)
{
throw new NotSupportedException("Only attribute routing is supported for JsonApiDotNetCore endpoints.");
}

ActionDescriptor expandedEndpoint = Clone(genericEndpoint);
var expandedEndpoint = Clone(genericEndpoint);

RemovePathParameter(expandedEndpoint.Parameters, "relationshipName");

Expand All @@ -179,11 +179,11 @@ private static List<ActionDescriptor> Expand(ActionDescriptor genericEndpoint, N

private static void UpdateBodyParameterDescriptor(ActionDescriptor endpoint, Type documentType, string? parameterName)
{
ControllerParameterDescriptor? requestBodyDescriptor = endpoint.GetBodyParameterDescriptor();
var requestBodyDescriptor = endpoint.GetBodyParameterDescriptor();

if (requestBodyDescriptor == null)
{
MethodInfo actionMethod = endpoint.GetActionMethod();
var actionMethod = endpoint.GetActionMethod();

throw new InvalidConfigurationException(
$"The action method '{actionMethod}' on type '{actionMethod.ReflectedType?.FullName}' contains no parameter with a [FromBody] attribute.");
Expand All @@ -195,7 +195,7 @@ private static void UpdateBodyParameterDescriptor(ActionDescriptor endpoint, Typ

private static ActionDescriptor Clone(ActionDescriptor descriptor)
{
ActionDescriptor clone = descriptor.MemberwiseClone();
var clone = descriptor.MemberwiseClone();
clone.AttributeRouteInfo = descriptor.AttributeRouteInfo!.MemberwiseClone();
clone.FilterDescriptors = descriptor.FilterDescriptors.Select(Clone).ToList();
clone.Parameters = descriptor.Parameters.Select(parameter => parameter.MemberwiseClone()).ToList();
Expand All @@ -204,7 +204,7 @@ private static ActionDescriptor Clone(ActionDescriptor descriptor)

private static FilterDescriptor Clone(FilterDescriptor descriptor)
{
IFilterMetadata clone = descriptor.Filter.MemberwiseClone();
var clone = descriptor.Filter.MemberwiseClone();

return new FilterDescriptor(clone, descriptor.Scope)
{
Expand All @@ -214,7 +214,7 @@ private static FilterDescriptor Clone(FilterDescriptor descriptor)

private static void RemovePathParameter(ICollection<ParameterDescriptor> parameters, string parameterName)
{
ParameterDescriptor descriptor = parameters.Single(parameterDescriptor => parameterDescriptor.Name == parameterName);
var descriptor = parameters.Single(parameterDescriptor => parameterDescriptor.Name == parameterName);
parameters.Remove(descriptor);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net10.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
Expand Down
Loading
Loading