Add support for dotnet 10 (#2229)

* Add dotnet10 as target framework and fix breaking changes

* Fix tests

* Fix tests for CI

* Fix typo
This commit is contained in:
Christian
2025-12-07 16:24:34 +01:00
committed by GitHub
parent d74d83453f
commit 1a3e97afec
12 changed files with 35 additions and 11 deletions
+3 -1
View File
@@ -17,6 +17,7 @@ jobs:
with:
dotnet-version: |
8.0.x
10.0.x
- name: Checkout code
uses: actions/checkout@v4
@@ -48,12 +49,13 @@ jobs:
with:
dotnet-version: |
8.0.x
10.0.x
- name: Checkout code
uses: actions/checkout@v4
- name: Execute tests
run: dotnet test --framework net8.0 --configuration Release Source/MQTTnet.Tests/MQTTnet.Tests.csproj
run: dotnet test --framework net10.0 --configuration Release Source/MQTTnet.Tests/MQTTnet.Tests.csproj
sign:
needs: build
+2 -5
View File
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<Product>MQTTnet</Product>
<Authors>The contributors of MQTTnet</Authors>
<Company>The contributors of MQTTnet</Company>
@@ -11,6 +11,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<NeutralLanguage>en-US</NeutralLanguage>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -24,10 +25,6 @@
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>recommended</AnalysisMode>
<AnalysisModeStyle>default</AnalysisModeStyle>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<EnableMSTestRunner>true</EnableMSTestRunner>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
+2
View File
@@ -59,10 +59,12 @@ public static class Server_TLS_Samples
certRequest.CertificateExtensions.Add(sanBuilder.Build());
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
#pragma warning disable SYSLIB0057
var pfxCertificate = new X509Certificate2(
certificate.Export(X509ContentType.Pfx),
(string)null!,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
#pragma warning restore SYSLIB0057
return pfxCertificate;
}
@@ -202,9 +202,14 @@ public sealed class MqttTcpServerListener : IDisposable
clientCertificate = sslStream.RemoteCertificate as X509Certificate2;
// TODO: Check why this export is needed. Is there something else in the RemoteCertificate as a X509Certificate2???
if (clientCertificate == null && sslStream.RemoteCertificate != null)
{
#if NET10_0_OR_GREATER
clientCertificate = X509CertificateLoader.LoadCertificate(sslStream.RemoteCertificate.Export(X509ContentType.Cert));
#else
clientCertificate = new X509Certificate2(sslStream.RemoteCertificate.Export(X509ContentType.Cert));
#endif
}
}
@@ -2,7 +2,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType>Full</DebugType>
<IsPackable>false</IsPackable>
</PropertyGroup>
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<LangVersion>default</LangVersion>
@@ -122,10 +122,12 @@ public sealed class HotSwapCerts_Tests
certRequest.CertificateExtensions.Add(sanBuilder.Build());
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
#pragma warning disable SYSLIB0057
var pfxCertificate = new X509Certificate2(
certificate.Export(X509ContentType.Pfx),
(string)null,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
#pragma warning restore SYSLIB0057
return pfxCertificate;
}
+3 -2
View File
@@ -1,5 +1,6 @@
#if DEBUG
using System.Globalization;
using MQTTnet.Internal;
using MQTTnet.Packets;
using MQTTnet.Protocol;
@@ -52,7 +53,7 @@ public sealed class Load_Tests : BaseTestClass
for (var j = 0; j < 1000; j++)
{
publishPacket.Topic = j.ToString();
publishPacket.Topic = j.ToString(CultureInfo.InvariantCulture);
await client.SendAsync(publishPacket, CancellationToken.None);
}
@@ -139,7 +140,7 @@ public sealed class Load_Tests : BaseTestClass
for (var j = 0; j < 1000; j++)
{
var message = applicationMessageBuilder.WithTopic(j.ToString()).Build();
var message = applicationMessageBuilder.WithTopic(j.ToString(CultureInfo.InvariantCulture)).Build();
await client.PublishAsync(message);
}
@@ -520,10 +520,11 @@ public sealed class SubscriptionTopicHashTests : IDisposable
static byte[] GetBytes(ulong value)
{
var bytes = BitConverter.GetBytes(value);
// Ensure that highest byte comes first for comparison left to right
if (BitConverter.IsLittleEndian)
{
return bytes.Reverse().ToArray();
bytes = bytes.AsEnumerable().Reverse().ToArray();
}
return bytes;
+2
View File
@@ -31,10 +31,12 @@ public sealed class Tls_Tests : BaseTestClass
certRequest.CertificateExtensions.Add(sanBuilder.Build());
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
#pragma warning disable SYSLIB0057
var pfxCertificate = new X509Certificate2(
certificate.Export(X509ContentType.Pfx),
(string)null,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
#pragma warning restore SYSLIB0057
return pfxCertificate;
}
@@ -14,6 +14,17 @@ public class BlobCertificateProvider(byte[] blob) : ICertificateProvider
public X509Certificate2 GetCertificate()
{
#if NET10_0_OR_GREATER
if (string.IsNullOrEmpty(Password))
{
return X509CertificateLoader.LoadCertificate(Blob);
}
return X509CertificateLoader.LoadPkcs12(Blob, Password);
#else
if (string.IsNullOrEmpty(Password))
{
// Use a different overload when no password is specified. Otherwise, the constructor will fail.
@@ -21,5 +32,7 @@ public class BlobCertificateProvider(byte[] blob) : ICertificateProvider
}
return new X509Certificate2(Blob, Password);
#endif
}
}
+1
View File
@@ -7,3 +7,4 @@
* Marked all projects as AOT compatible
* Restored the strong name of the nugets
* Embedded license file in all nugets (#2197, thanks to @JensNordenbro)
* Added support for dotnet10