Skip to content

Commit 4c7bd35

Browse files
authored
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
1 parent d3641a0 commit 4c7bd35

File tree

11 files changed

+50
-23
lines changed

11 files changed

+50
-23
lines changed

appveyor.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ for:
1212
- image: Ubuntu2204
1313

1414
install:
15-
- sh: sudo apt-get update && sudo apt-get install -y dotnet-sdk-7.0=7.0.403-1
15+
- sh: sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0=8.0.100-1
1616

1717
before_build:
1818
- sh: mkdir artifacts -p
1919

2020
build_script:
2121
- echo build
22-
- dotnet build Renci.SshNet.sln -c Debug -f net7.0
22+
- dotnet build Renci.SshNet.sln -c Debug -f net8.0
2323

2424
test_script:
2525
- sh: echo "Run unit tests"
26-
- 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
26+
- 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
2727
- sh: echo "Run integration tests"
28-
- 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
28+
- 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
2929

3030
# on_failure:
3131
# - sh: appveyor PushArtifact artifacts/tcpdump.pcap
@@ -36,7 +36,7 @@ for:
3636
- image: Visual Studio 2022
3737

3838
install:
39-
- ps: choco install dotnet-7.0-sdk --version=7.0.403
39+
- ps: choco install dotnet-8.0-sdk --version=8.0.100
4040

4141
before_build:
4242
- ps: mkdir artifacts -f
@@ -46,8 +46,8 @@ for:
4646
- dotnet build Renci.SshNet.sln -c Debug
4747

4848
test_script:
49-
- ps: echo "Run unit tests for .NET 7.0"
50-
- 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
49+
- ps: echo "Run unit tests for .NET 8.0"
50+
- 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
5151
- ps: echo "Run unit tests for .NET Framework 4.6.2"
5252
- 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
5353

build/nuget/SSH.NET.nuspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<group targetFramework="net7.0">
3030
<dependency id="SshNet.Security.Cryptography" version="[1.3.0]" />
3131
</group>
32+
<group targetFramework="net8.0">
33+
<dependency id="SshNet.Security.Cryptography" version="[1.3.0]" />
34+
</group>
3235
</dependencies>
3336
</metadata>
34-
</package>
37+
</package>

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "7.0.403",
3+
"version": "8.0.100",
44
"rollForward": "latestMajor"
55
}
6-
}
6+
}

src/Renci.SshNet/Common/SshData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,14 @@ protected byte[] ReadBytes(int length)
158158
var data = new byte[length];
159159
var bytesRead = _stream.Read(data, 0, length);
160160

161+
#if NET8_0_OR_GREATER
162+
ArgumentOutOfRangeException.ThrowIfGreaterThan(length, bytesRead);
163+
#else
161164
if (bytesRead < length)
162165
{
163166
throw new ArgumentOutOfRangeException(nameof(length));
164167
}
168+
#endif
165169

166170
return data;
167171
}

src/Renci.SshNet/Renci.SshNet.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
<PropertyGroup>
33
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
44
<AssemblyName>Renci.SshNet</AssemblyName>
5-
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
5+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
99
<DefineConstants>$(DefineConstants);FEATURE_BINARY_SERIALIZATION;FEATURE_SOCKET_EAP;FEATURE_SOCKET_APM;FEATURE_DNS_SYNC;FEATURE_HASH_RIPEMD160_CREATE;FEATURE_HMAC_RIPEMD160</DefineConstants>
1010
</PropertyGroup>
1111

12-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' ">
12+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0' ">
1313
<PackageReference Include="SshNet.Security.Cryptography" Version="[1.3.0]" />
1414
</ItemGroup>
1515

1616
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">
1717
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
1818
</ItemGroup>
1919

20-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' ">
20+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0' ">
2121
<DefineConstants>$(DefineConstants);FEATURE_SOCKET_TAP;FEATURE_SOCKET_APM;FEATURE_SOCKET_EAP;FEATURE_DNS_SYNC;FEATURE_DNS_APM;FEATURE_DNS_TAP</DefineConstants>
2222
</PropertyGroup>
2323
</Project>

src/Renci.SshNet/Sftp/SftpFileStream.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ public override int Read(byte[] buffer, int offset, int count)
519519
throw new ArgumentNullException(nameof(buffer));
520520
}
521521

522+
#if NET8_0_OR_GREATER
523+
ArgumentOutOfRangeException.ThrowIfNegative(offset);
524+
ArgumentOutOfRangeException.ThrowIfNegative(count);
525+
#else
522526
if (offset < 0)
523527
{
524528
throw new ArgumentOutOfRangeException(nameof(offset));
@@ -528,7 +532,7 @@ public override int Read(byte[] buffer, int offset, int count)
528532
{
529533
throw new ArgumentOutOfRangeException(nameof(count));
530534
}
531-
535+
#endif
532536
if ((buffer.Length - offset) < count)
533537
{
534538
throw new ArgumentException("Invalid array range.");
@@ -660,6 +664,10 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
660664
throw new ArgumentNullException(nameof(buffer));
661665
}
662666

667+
#if NET8_0_OR_GREATER
668+
ArgumentOutOfRangeException.ThrowIfNegative(offset);
669+
ArgumentOutOfRangeException.ThrowIfNegative(count);
670+
#else
663671
if (offset < 0)
664672
{
665673
throw new ArgumentOutOfRangeException(nameof(offset));
@@ -669,7 +677,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
669677
{
670678
throw new ArgumentOutOfRangeException(nameof(count));
671679
}
672-
680+
#endif
673681
if ((buffer.Length - offset) < count)
674682
{
675683
throw new ArgumentException("Invalid array range.");
@@ -951,10 +959,14 @@ public override long Seek(long offset, SeekOrigin origin)
951959
/// </remarks>
952960
public override void SetLength(long value)
953961
{
962+
#if NET8_0_OR_GREATER
963+
ArgumentOutOfRangeException.ThrowIfNegative(value);
964+
#else
954965
if (value < 0)
955966
{
956967
throw new ArgumentOutOfRangeException(nameof(value));
957968
}
969+
#endif
958970

959971
// Lock down the file stream while we do this.
960972
lock (_lock)
@@ -1005,6 +1017,10 @@ public override void Write(byte[] buffer, int offset, int count)
10051017
throw new ArgumentNullException(nameof(buffer));
10061018
}
10071019

1020+
#if NET8_0_OR_GREATER
1021+
ArgumentOutOfRangeException.ThrowIfNegative(offset);
1022+
ArgumentOutOfRangeException.ThrowIfNegative(count);
1023+
#else
10081024
if (offset < 0)
10091025
{
10101026
throw new ArgumentOutOfRangeException(nameof(offset));
@@ -1014,7 +1030,7 @@ public override void Write(byte[] buffer, int offset, int count)
10141030
{
10151031
throw new ArgumentOutOfRangeException(nameof(count));
10161032
}
1017-
1033+
#endif
10181034
if ((buffer.Length - offset) < count)
10191035
{
10201036
throw new ArgumentException("Invalid array range.");
@@ -1104,6 +1120,10 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
11041120
throw new ArgumentNullException(nameof(buffer));
11051121
}
11061122

1123+
#if NET8_0_OR_GREATER
1124+
ArgumentOutOfRangeException.ThrowIfNegative(offset);
1125+
ArgumentOutOfRangeException.ThrowIfNegative(count);
1126+
#else
11071127
if (offset < 0)
11081128
{
11091129
throw new ArgumentOutOfRangeException(nameof(offset));
@@ -1113,7 +1133,7 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
11131133
{
11141134
throw new ArgumentOutOfRangeException(nameof(count));
11151135
}
1116-
1136+
#endif
11171137
if ((buffer.Length - offset) < count)
11181138
{
11191139
throw new ArgumentException("Invalid array range.");

test/Renci.SshNet.Benchmarks/Renci.SshNet.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<IsPackable>false</IsPackable>
77
<IsTestProject>true</IsTestProject>

test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net7.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045</NoWarn>

test/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAliveInterval_NotNegativeOne.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ protected override void Act()
5656
{
5757
_client.KeepAliveInterval = _keepAliveInterval;
5858

59-
// allow keep-alive to be sent a few times. .NET 7 is faster and
59+
// allow keep-alive to be sent a few times. .NET 8 is faster and
6060
// we need to wait less because we want exactly three messages in a session.
6161
#if NETFRAMEWORK
6262
Thread.Sleep(195);
6363
#else
64-
Thread.Sleep(180);
64+
Thread.Sleep(170);
6565
#endif
6666
}
6767

0 commit comments

Comments
 (0)