mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 01:05:42 +00:00
Add support for .NET 8.0 (#1255)
* Add support for .NET 8.0 * Fix CA1512: Use 'ArgumentOutOfRangeException.ThrowIfNegative' instead of explicitly throwing a new exception instance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1512) * Use `ThrowIfGreaterThan` instead of `ThrowIfNegative`+calculation, to supply the correct parameter name. * .NET 8 is faster :-) * Use the explicit version, in case newer version SDK breaks our tests
This commit is contained in:
+7
-7
@@ -12,20 +12,20 @@ for:
|
||||
- image: Ubuntu2204
|
||||
|
||||
install:
|
||||
- sh: sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0=7.0.403-1
|
||||
- sh: sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0=8.0.100-1
|
||||
|
||||
before_build:
|
||||
- sh: mkdir artifacts -p
|
||||
|
||||
build_script:
|
||||
- echo build
|
||||
- dotnet build Renci.SshNet.sln -c Debug -f net7.0
|
||||
- dotnet build Renci.SshNet.sln -c Debug -f net8.0
|
||||
|
||||
test_script:
|
||||
- sh: echo "Run unit tests"
|
||||
- sh: dotnet test -f net7.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_unit_test_net_7_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_unit_test_net_7_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
|
||||
- sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_unit_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_unit_test_net_8_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
|
||||
- sh: echo "Run integration tests"
|
||||
- sh: dotnet test -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_7_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_7_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
|
||||
- sh: dotnet test -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_8_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
|
||||
|
||||
# on_failure:
|
||||
# - sh: appveyor PushArtifact artifacts/tcpdump.pcap
|
||||
@@ -36,7 +36,7 @@ for:
|
||||
- image: Visual Studio 2022
|
||||
|
||||
install:
|
||||
- ps: choco install dotnet-7.0-sdk --version=7.0.403
|
||||
- ps: choco install dotnet-8.0-sdk --version=8.0.100
|
||||
|
||||
before_build:
|
||||
- ps: mkdir artifacts -f
|
||||
@@ -46,8 +46,8 @@ for:
|
||||
- dotnet build Renci.SshNet.sln -c Debug
|
||||
|
||||
test_script:
|
||||
- ps: echo "Run unit tests for .NET 7.0"
|
||||
- ps: dotnet test -f net7.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=windows_unit_test_net_7_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/windows_unit_test_net_7_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
|
||||
- ps: echo "Run unit tests for .NET 8.0"
|
||||
- ps: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=windows_unit_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/windows_unit_test_net_8_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
|
||||
- ps: echo "Run unit tests for .NET Framework 4.6.2"
|
||||
- ps: dotnet test -f net462 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=windows_unit_test_net_4_6_2_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/windows_unit_test_net_4_6_2_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
<group targetFramework="net7.0">
|
||||
<dependency id="SshNet.Security.Cryptography" version="[1.3.0]" />
|
||||
</group>
|
||||
<group targetFramework="net8.0">
|
||||
<dependency id="SshNet.Security.Cryptography" version="[1.3.0]" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
||||
</package>
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "7.0.403",
|
||||
"version": "8.0.100",
|
||||
"rollForward": "latestMajor"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,10 +158,14 @@ namespace Renci.SshNet.Common
|
||||
var data = new byte[length];
|
||||
var bytesRead = _stream.Read(data, 0, length);
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(length, bytesRead);
|
||||
#else
|
||||
if (bytesRead < length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(length));
|
||||
}
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
<PropertyGroup>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AssemblyName>Renci.SshNet</AssemblyName>
|
||||
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
|
||||
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
|
||||
<DefineConstants>$(DefineConstants);FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' ">
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0' ">
|
||||
<PackageReference Include="SshNet.Security.Cryptography" Version="[1.3.0]" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' ">
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0' ">
|
||||
<DefineConstants>$(DefineConstants);FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP</DefineConstants>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -519,6 +519,10 @@ namespace Renci.SshNet.Sftp
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(offset);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
||||
#else
|
||||
if (offset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
@@ -528,7 +532,7 @@ namespace Renci.SshNet.Sftp
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
#endif
|
||||
if ((buffer.Length - offset) < count)
|
||||
{
|
||||
throw new ArgumentException("Invalid array range.");
|
||||
@@ -660,6 +664,10 @@ namespace Renci.SshNet.Sftp
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(offset);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
||||
#else
|
||||
if (offset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
@@ -669,7 +677,7 @@ namespace Renci.SshNet.Sftp
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
#endif
|
||||
if ((buffer.Length - offset) < count)
|
||||
{
|
||||
throw new ArgumentException("Invalid array range.");
|
||||
@@ -951,10 +959,14 @@ namespace Renci.SshNet.Sftp
|
||||
/// </remarks>
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(value);
|
||||
#else
|
||||
if (value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Lock down the file stream while we do this.
|
||||
lock (_lock)
|
||||
@@ -1005,6 +1017,10 @@ namespace Renci.SshNet.Sftp
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(offset);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
||||
#else
|
||||
if (offset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
@@ -1014,7 +1030,7 @@ namespace Renci.SshNet.Sftp
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
#endif
|
||||
if ((buffer.Length - offset) < count)
|
||||
{
|
||||
throw new ArgumentException("Invalid array range.");
|
||||
@@ -1104,6 +1120,10 @@ namespace Renci.SshNet.Sftp
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(offset);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
||||
#else
|
||||
if (offset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset));
|
||||
@@ -1113,7 +1133,7 @@ namespace Renci.SshNet.Sftp
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
#endif
|
||||
if ((buffer.Length - offset) < count)
|
||||
{
|
||||
throw new ArgumentException("Invalid array range.");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045</NoWarn>
|
||||
|
||||
+2
-2
@@ -56,12 +56,12 @@ namespace Renci.SshNet.Tests.Classes
|
||||
{
|
||||
_client.KeepAliveInterval = _keepAliveInterval;
|
||||
|
||||
// allow keep-alive to be sent a few times. .NET 7 is faster and
|
||||
// allow keep-alive to be sent a few times. .NET 8 is faster and
|
||||
// we need to wait less because we want exactly three messages in a session.
|
||||
#if NETFRAMEWORK
|
||||
Thread.Sleep(195);
|
||||
#else
|
||||
Thread.Sleep(180);
|
||||
Thread.Sleep(170);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
|
||||
<TargetFrameworks>net462;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user