Skip to content

Commit 752b1db

Browse files
mus65Rob-Hague
andauthored
Add .NET 9 target (#1480)
* Add .NET 9 target * Disable SonarSource S3236 This following change in the runtime now causes this analyzer to complain about some Debug.Assert calls which doesn't make sense. https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview7/libraries.md#debugassert-now-reports-assert-condition-by-default https://rules.sonarsource.com/csharp/RSPEC-3236/ * make use of .NET 9 Lock type see dotnet/runtime#34812 * Define own Lock type to avoid ifdefs * revert irrelevant style changes * update global.json * Keep net8.0 target in IntegrationTests Co-authored-by: Rob Hague <[email protected]> * fix Package Downgrade Warning for some reason this happens starting with .NET 9.0 RC2: /home/mus/git/SSH.NET/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj : error NU1605: Warning As Error: Detected package downgrade: BouncyCastle.Cryptography from 2.4.0 to 2.3.1. Reference the package directly from the project to select a different version. Renci.SshNet.IntegrationTests -> SSH.NET 1.0.0 -> BouncyCastle.Cryptography (>= 2.4.0) Renci.SshNet.IntegrationTests -> Testcontainers 3.10.0 -> BouncyCastle.Cryptography (>= 2.3.1) * update global.json to RC2 * update global.json to .NET 9 GA * update GitHub Actions for .NET 9 --------- Co-authored-by: Rob Hague <[email protected]>
1 parent f65ca44 commit 752b1db

16 files changed

+57
-27
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ dotnet_diagnostic.S2971.severity = none
195195
# This is rather harmless.
196196
dotnet_diagnostic.S3218.severity = none
197197

198+
# S3236: Remove this argument from the method call; it hides the caller information.
199+
dotnet_diagnostic.S3236.severity = none
200+
198201
# S3267: Loops should be simplified with "LINQ" expressions
199202
# https://rules.sonarsource.com/csharp/RSPEC-3267
200203
#

.github/workflows/build.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,39 @@ jobs:
1717
- name: Setup .NET
1818
uses: actions/setup-dotnet@v4
1919
with:
20-
dotnet-version: 8.0.x
20+
dotnet-version: 9.0.x
2121

2222
- name: Build Unit Tests .NET
23-
run: dotnet build -f net8.0 test/Renci.SshNet.Tests/
23+
run: dotnet build -f net9.0 test/Renci.SshNet.Tests/
2424

2525
- name: Build IntegrationTests .NET
26-
run: dotnet build -f net8.0 test/Renci.SshNet.IntegrationTests/
26+
run: dotnet build -f net9.0 test/Renci.SshNet.IntegrationTests/
2727

2828
- name: Build IntegrationTests .NET Framework
2929
run: dotnet build -f net48 test/Renci.SshNet.IntegrationTests/
3030

3131
- name: Run Unit Tests .NET
3232
run: |
3333
dotnet test \
34-
-f net8.0 \
34+
-f net9.0 \
3535
--no-build \
3636
--logger "console;verbosity=normal" \
3737
--logger GitHubActions \
3838
-p:CollectCoverage=true \
3939
-p:CoverletOutputFormat=cobertura \
40-
-p:CoverletOutput=../../coverlet/linux_unit_test_net_8_coverage.xml \
40+
-p:CoverletOutput=../../coverlet/linux_unit_test_net_9_coverage.xml \
4141
test/Renci.SshNet.Tests/
4242
4343
- name: Run Integration Tests .NET
4444
run: |
4545
dotnet test \
46-
-f net8.0 \
46+
-f net9.0 \
4747
--no-build \
4848
--logger "console;verbosity=normal" \
4949
--logger GitHubActions \
5050
-p:CollectCoverage=true \
5151
-p:CoverletOutputFormat=cobertura \
52-
-p:CoverletOutput=../../coverlet/linux_integration_test_net_8_coverage.xml \
52+
-p:CoverletOutput=../../coverlet/linux_integration_test_net_9_coverage.xml \
5353
test/Renci.SshNet.IntegrationTests/
5454
5555
# Also run a subset of the integration tests targeting netfx using mono. This is a temporary measure to get
@@ -111,13 +111,13 @@ jobs:
111111
- name: Run Unit Tests .NET
112112
run: |
113113
dotnet test `
114-
-f net8.0 `
114+
-f net9.0 `
115115
--no-build `
116116
--logger "console;verbosity=normal" `
117117
--logger GitHubActions `
118118
-p:CollectCoverage=true `
119119
-p:CoverletOutputFormat=cobertura `
120-
-p:CoverletOutput=../../coverlet/windows_unit_test_net_8_coverage.xml `
120+
-p:CoverletOutput=../../coverlet/windows_unit_test_net_9_coverage.xml `
121121
test/Renci.SshNet.Tests/
122122
123123
- name: Run Unit Tests .NET Framework

global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.100",
3+
"version": "9.0.100",
44
"rollForward": "latestMajor"
55
}
66
}

src/Renci.SshNet/Channels/Channel.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Renci.SshNet.Channels
1414
/// </summary>
1515
internal abstract class Channel : IChannel
1616
{
17-
private readonly object _serverWindowSizeLock = new object();
18-
private readonly object _messagingLock = new object();
17+
private readonly Lock _serverWindowSizeLock = new Lock();
18+
private readonly Lock _messagingLock = new Lock();
1919
private readonly uint _initialWindowSize;
2020
private readonly ISession _session;
2121
private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(initialState: false);

src/Renci.SshNet/Channels/ChannelDirectTcpip.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Renci.SshNet.Channels
1414
/// </summary>
1515
internal sealed class ChannelDirectTcpip : ClientChannel, IChannelDirectTcpip
1616
{
17-
private readonly object _socketLock = new object();
17+
private readonly Lock _socketLock = new Lock();
1818

1919
private EventWaitHandle _channelOpen = new AutoResetEvent(initialState: false);
2020
private EventWaitHandle _channelData = new AutoResetEvent(initialState: false);

src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Net;
33
using System.Net.Sockets;
4+
#if NET9_0_OR_GREATER
5+
using System.Threading;
6+
#endif
47

58
using Renci.SshNet.Abstractions;
69
using Renci.SshNet.Common;
@@ -13,7 +16,7 @@ namespace Renci.SshNet.Channels
1316
/// </summary>
1417
internal sealed class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip
1518
{
16-
private readonly object _socketShutdownAndCloseLock = new object();
19+
private readonly Lock _socketShutdownAndCloseLock = new Lock();
1720
private Socket _socket;
1821
private IForwardedPort _forwardedPort;
1922

src/Renci.SshNet/Common/Lock.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if !NET9_0_OR_GREATER
2+
using System.Threading;
3+
4+
namespace Renci.SshNet.Common
5+
{
6+
internal sealed class Lock
7+
{
8+
public bool TryEnter()
9+
{
10+
return Monitor.TryEnter(this);
11+
}
12+
13+
public void Exit()
14+
{
15+
Monitor.Exit(this);
16+
}
17+
}
18+
}
19+
#endif

src/Renci.SshNet/Renci.SshNet.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<AssemblyName>Renci.SshNet</AssemblyName>
55
<Product>SSH.NET</Product>
66
<AssemblyTitle>SSH.NET</AssemblyTitle>
7-
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
7+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
88
</PropertyGroup>
99

1010
<PropertyGroup>

src/Renci.SshNet/Session.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class Session : ISession
8080
/// Holds an object that is used to ensure only a single thread can read from
8181
/// <see cref="_socket"/> at any given time.
8282
/// </summary>
83-
private readonly object _socketReadLock = new object();
83+
private readonly Lock _socketReadLock = new Lock();
8484

8585
/// <summary>
8686
/// Holds an object that is used to ensure only a single thread can write to
@@ -90,7 +90,7 @@ public class Session : ISession
9090
/// This is also used to ensure that <see cref="_outboundPacketSequence"/> is
9191
/// incremented atomatically.
9292
/// </remarks>
93-
private readonly object _socketWriteLock = new object();
93+
private readonly Lock _socketWriteLock = new Lock();
9494

9595
/// <summary>
9696
/// Holds an object that is used to ensure only a single thread can dispose
@@ -1894,7 +1894,7 @@ private bool IsSocketConnected()
18941894
return false;
18951895
}
18961896

1897-
if (!Monitor.TryEnter(_socketReadLock))
1897+
if (!_socketReadLock.TryEnter())
18981898
{
18991899
return true;
19001900
}
@@ -1906,7 +1906,7 @@ private bool IsSocketConnected()
19061906
}
19071907
finally
19081908
{
1909-
Monitor.Exit(_socketReadLock);
1909+
_socketReadLock.Exit();
19101910
}
19111911
}
19121912
finally

src/Renci.SshNet/Sftp/SftpFileStream.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Renci.SshNet.Sftp
1818
#pragma warning restore IDE0079
1919
public class SftpFileStream : Stream
2020
{
21-
private readonly object _lock = new object();
21+
private readonly Lock _lock = new Lock();
2222
private readonly int _readBufferSize;
2323
private readonly int _writeBufferSize;
2424

src/Renci.SshNet/SshMessageFactory.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
#if NET9_0_OR_GREATER
5+
using System.Threading;
6+
#endif
47

58
using Renci.SshNet.Common;
69
using Renci.SshNet.Messages;
@@ -14,7 +17,7 @@ internal sealed class SshMessageFactory
1417
{
1518
private readonly MessageMetadata[] _enabledMessagesByNumber;
1619
private readonly bool[] _activatedMessagesById;
17-
private readonly object _lock = new object();
20+
private readonly Lock _lock = new Lock();
1821

1922
internal static readonly MessageMetadata[] AllMessages = new MessageMetadata[]
2023
{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

test/Renci.SshNet.IntegrationBenchmarks/Renci.SshNet.IntegrationBenchmarks.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net48;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net48;net8.0;net9.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<IsTestProject>true</IsTestProject>
77
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010</NoWarn>

test/Renci.SshNet.Tests/Common/AsyncSocketListener.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Net;
55
using System.Net.Sockets;
66
using System.Threading;
7+
8+
using Renci.SshNet.Common;
79
#pragma warning restore IDE0005
810

911
namespace Renci.SshNet.Tests.Common
@@ -13,7 +15,7 @@ public class AsyncSocketListener : IDisposable
1315
private readonly IPEndPoint _endPoint;
1416
private readonly ManualResetEvent _acceptCallbackDone;
1517
private readonly List<Socket> _connectedClients;
16-
private readonly object _syncLock;
18+
private readonly Lock _syncLock;
1719
private Socket _listener;
1820
private Thread _receiveThread;
1921
private bool _started;
@@ -31,7 +33,7 @@ public AsyncSocketListener(IPEndPoint endPoint)
3133
_endPoint = endPoint;
3234
_acceptCallbackDone = new ManualResetEvent(false);
3335
_connectedClients = new List<Socket>();
34-
_syncLock = new object();
36+
_syncLock = new Lock();
3537
ShutdownRemoteCommunicationSocket = true;
3638
}
3739

test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net462;net6.0;net7.0;net8.0</TargetFrameworks>
4+
<TargetFrameworks>net462;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

0 commit comments

Comments
 (0)