mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
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:
@@ -17,6 +17,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
dotnet-version: |
|
dotnet-version: |
|
||||||
8.0.x
|
8.0.x
|
||||||
|
10.0.x
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -48,12 +49,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
dotnet-version: |
|
dotnet-version: |
|
||||||
8.0.x
|
8.0.x
|
||||||
|
10.0.x
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Execute tests
|
- 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:
|
sign:
|
||||||
needs: build
|
needs: build
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
|
||||||
<Product>MQTTnet</Product>
|
<Product>MQTTnet</Product>
|
||||||
<Authors>The contributors of MQTTnet</Authors>
|
<Authors>The contributors of MQTTnet</Authors>
|
||||||
<Company>The contributors of MQTTnet</Company>
|
<Company>The contributors of MQTTnet</Company>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
|
|
||||||
<NeutralLanguage>en-US</NeutralLanguage>
|
<NeutralLanguage>en-US</NeutralLanguage>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
@@ -24,10 +25,6 @@
|
|||||||
<AnalysisLevel>latest</AnalysisLevel>
|
<AnalysisLevel>latest</AnalysisLevel>
|
||||||
<AnalysisMode>recommended</AnalysisMode>
|
<AnalysisMode>recommended</AnalysisMode>
|
||||||
<AnalysisModeStyle>default</AnalysisModeStyle>
|
<AnalysisModeStyle>default</AnalysisModeStyle>
|
||||||
|
|
||||||
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
|
|
||||||
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
|
|
||||||
<EnableMSTestRunner>true</EnableMSTestRunner>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
|
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
|
||||||
|
|||||||
@@ -59,10 +59,12 @@ public static class Server_TLS_Samples
|
|||||||
certRequest.CertificateExtensions.Add(sanBuilder.Build());
|
certRequest.CertificateExtensions.Add(sanBuilder.Build());
|
||||||
|
|
||||||
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
|
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
|
||||||
|
#pragma warning disable SYSLIB0057
|
||||||
var pfxCertificate = new X509Certificate2(
|
var pfxCertificate = new X509Certificate2(
|
||||||
certificate.Export(X509ContentType.Pfx),
|
certificate.Export(X509ContentType.Pfx),
|
||||||
(string)null!,
|
(string)null!,
|
||||||
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
|
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
|
||||||
|
#pragma warning restore SYSLIB0057
|
||||||
|
|
||||||
return pfxCertificate;
|
return pfxCertificate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,9 +202,14 @@ public sealed class MqttTcpServerListener : IDisposable
|
|||||||
|
|
||||||
clientCertificate = sslStream.RemoteCertificate as X509Certificate2;
|
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 (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));
|
clientCertificate = new X509Certificate2(sslStream.RemoteCertificate.Export(X509ContentType.Cert));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<DebugType>Full</DebugType>
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<LangVersion>default</LangVersion>
|
<LangVersion>default</LangVersion>
|
||||||
|
|||||||
@@ -122,10 +122,12 @@ public sealed class HotSwapCerts_Tests
|
|||||||
certRequest.CertificateExtensions.Add(sanBuilder.Build());
|
certRequest.CertificateExtensions.Add(sanBuilder.Build());
|
||||||
|
|
||||||
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
|
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
|
||||||
|
#pragma warning disable SYSLIB0057
|
||||||
var pfxCertificate = new X509Certificate2(
|
var pfxCertificate = new X509Certificate2(
|
||||||
certificate.Export(X509ContentType.Pfx),
|
certificate.Export(X509ContentType.Pfx),
|
||||||
(string)null,
|
(string)null,
|
||||||
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
|
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
|
||||||
|
#pragma warning restore SYSLIB0057
|
||||||
|
|
||||||
return pfxCertificate;
|
return pfxCertificate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|
||||||
|
using System.Globalization;
|
||||||
using MQTTnet.Internal;
|
using MQTTnet.Internal;
|
||||||
using MQTTnet.Packets;
|
using MQTTnet.Packets;
|
||||||
using MQTTnet.Protocol;
|
using MQTTnet.Protocol;
|
||||||
@@ -52,7 +53,7 @@ public sealed class Load_Tests : BaseTestClass
|
|||||||
|
|
||||||
for (var j = 0; j < 1000; j++)
|
for (var j = 0; j < 1000; j++)
|
||||||
{
|
{
|
||||||
publishPacket.Topic = j.ToString();
|
publishPacket.Topic = j.ToString(CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
await client.SendAsync(publishPacket, CancellationToken.None);
|
await client.SendAsync(publishPacket, CancellationToken.None);
|
||||||
}
|
}
|
||||||
@@ -139,7 +140,7 @@ public sealed class Load_Tests : BaseTestClass
|
|||||||
|
|
||||||
for (var j = 0; j < 1000; j++)
|
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);
|
await client.PublishAsync(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -520,10 +520,11 @@ public sealed class SubscriptionTopicHashTests : IDisposable
|
|||||||
static byte[] GetBytes(ulong value)
|
static byte[] GetBytes(ulong value)
|
||||||
{
|
{
|
||||||
var bytes = BitConverter.GetBytes(value);
|
var bytes = BitConverter.GetBytes(value);
|
||||||
|
|
||||||
// Ensure that highest byte comes first for comparison left to right
|
// Ensure that highest byte comes first for comparison left to right
|
||||||
if (BitConverter.IsLittleEndian)
|
if (BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
return bytes.Reverse().ToArray();
|
bytes = bytes.AsEnumerable().Reverse().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ public sealed class Tls_Tests : BaseTestClass
|
|||||||
certRequest.CertificateExtensions.Add(sanBuilder.Build());
|
certRequest.CertificateExtensions.Add(sanBuilder.Build());
|
||||||
|
|
||||||
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
|
using var certificate = certRequest.CreateSelfSigned(DateTimeOffset.Now.AddMinutes(-10), DateTimeOffset.Now.AddMinutes(10));
|
||||||
|
#pragma warning disable SYSLIB0057
|
||||||
var pfxCertificate = new X509Certificate2(
|
var pfxCertificate = new X509Certificate2(
|
||||||
certificate.Export(X509ContentType.Pfx),
|
certificate.Export(X509ContentType.Pfx),
|
||||||
(string)null,
|
(string)null,
|
||||||
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
|
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
|
||||||
|
#pragma warning restore SYSLIB0057
|
||||||
|
|
||||||
return pfxCertificate;
|
return pfxCertificate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,17 @@ public class BlobCertificateProvider(byte[] blob) : ICertificateProvider
|
|||||||
|
|
||||||
public X509Certificate2 GetCertificate()
|
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))
|
if (string.IsNullOrEmpty(Password))
|
||||||
{
|
{
|
||||||
// Use a different overload when no password is specified. Otherwise, the constructor will fail.
|
// 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);
|
return new X509Certificate2(Blob, Password);
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,3 +7,4 @@
|
|||||||
* Marked all projects as AOT compatible
|
* Marked all projects as AOT compatible
|
||||||
* Restored the strong name of the nugets
|
* Restored the strong name of the nugets
|
||||||
* Embedded license file in all nugets (#2197, thanks to @JensNordenbro)
|
* Embedded license file in all nugets (#2197, thanks to @JensNordenbro)
|
||||||
|
* Added support for dotnet10
|
||||||
|
|||||||
Reference in New Issue
Block a user