Skip to content

Drop netstandard2.1 target #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ OpenSSH certificate authentication is supported for all of the above, e.g. ssh-e

**SSH.NET** supports the following target frameworks:
* .NETFramework 4.6.2 (and higher)
* .NET Standard 2.0 and 2.1
* .NET Standard 2.0
* .NET 8 (and higher)

## Building the library
Expand Down
8 changes: 0 additions & 8 deletions src/Renci.SshNet/Abstractions/SocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ public static async Task ConnectAsync(this Socket socket, EndPoint remoteEndpoin
{
args.RemoteEndPoint = remoteEndpoint;

#if NETSTANDARD2_1
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
#else
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false))
#endif
{
await args.ExecuteAsync(socket.ConnectAsync);
}
Expand All @@ -112,11 +108,7 @@ public static async Task<int> ReceiveAsync(this Socket socket, byte[] buffer, in
{
args.SetBuffer(buffer, offset, length);

#if NETSTANDARD2_1
await using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
#else
using (cancellationToken.Register(o => ((AwaitableSocketAsyncEventArgs)o).SetCancelled(), args, useSynchronizationContext: false))
#endif
{
await args.ExecuteAsync(socket.ReceiveAsync);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Abstractions/StreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0
#if !NET
using System;
using System.IO;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/ClientAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private bool TryAuthenticate(ISession session,
{
authenticationException = new SshAuthenticationException(string.Format(CultureInfo.InvariantCulture,
"No suitable authentication method found to complete authentication ({0}).",
#if NET || NETSTANDARD2_1
#if NET
string.Join(',', allowedAuthenticationMethods)))
#else
string.Join(",", allowedAuthenticationMethods)))
Expand Down
10 changes: 5 additions & 5 deletions src/Renci.SshNet/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static ServiceName ToServiceName(this byte[] data)

internal static BigInteger ToBigInteger(this ReadOnlySpan<byte> data)
{
#if NETSTANDARD2_1 || NET
#if NET
return new BigInteger(data, isBigEndian: true);
#else
var reversed = data.ToArray();
Expand All @@ -61,7 +61,7 @@ internal static BigInteger ToBigInteger(this ReadOnlySpan<byte> data)

internal static BigInteger ToBigInteger(this byte[] data)
{
#if NETSTANDARD2_1 || NET
#if NET
return new BigInteger(data, isBigEndian: true);
#else
var reversed = new byte[data.Length];
Expand All @@ -76,7 +76,7 @@ internal static BigInteger ToBigInteger(this byte[] data)
/// </summary>
public static BigInteger ToBigInteger2(this byte[] data)
{
#if NETSTANDARD2_1 || NET
#if NET
return new BigInteger(data, isBigEndian: true, isUnsigned: true);
#else
if ((data[0] & (1 << 7)) != 0)
Expand All @@ -91,7 +91,7 @@ public static BigInteger ToBigInteger2(this byte[] data)
#endif
}

#if NETFRAMEWORK || NETSTANDARD2_0
#if !NET
public static byte[] ToByteArray(this BigInteger bigInt, bool isUnsigned = false, bool isBigEndian = false)
{
var data = bigInt.ToByteArray();
Expand Down Expand Up @@ -361,7 +361,7 @@ internal static string Join(this IEnumerable<string> values, string separator)
return string.Join(separator, values);
}

#if NETFRAMEWORK || NETSTANDARD2_0
#if !NET
internal static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
if (!dictionary.ContainsKey(key))
Expand Down
6 changes: 3 additions & 3 deletions src/Renci.SshNet/Common/PipeStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override int Read(byte[] buffer, int offset, int count)
return Read(buffer.AsSpan(offset, count));
}

#if NETSTANDARD2_1 || NET
#if NET
/// <inheritdoc/>
public override int Read(Span<byte> buffer)
#else
Expand Down Expand Up @@ -99,7 +99,7 @@ public override void Write(byte[] buffer, int offset, int count)
}
}

#if NETSTANDARD2_1 || NET
#if NET
/// <inheritdoc/>
public override void Write(ReadOnlySpan<byte> buffer)
{
Expand Down Expand Up @@ -157,7 +157,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
return WriteAsync(buffer.AsMemory(offset, count), cancellationToken).AsTask();
}

#if NETSTANDARD2_1 || NET
#if NET
/// <inheritdoc/>
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
#else
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Common/SshData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ protected void Write(BigInteger data)
/// <param name="data">name-list data to write.</param>
protected void Write(string[] data)
{
#if NET || NETSTANDARD2_1
#if NET
Write(string.Join(',', data), Ascii);
#else
Write(string.Join(",", data), Ascii);
Expand Down
6 changes: 3 additions & 3 deletions src/Renci.SshNet/Common/SshDataStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public bool IsEndOfData
}
}

#if NETFRAMEWORK || NETSTANDARD2_0
#if !NET
private void Write(ReadOnlySpan<byte> buffer)
{
var sharedBuffer = System.Buffers.ArrayPool<byte>.Shared.Rent(buffer.Length);
Expand Down Expand Up @@ -129,7 +129,7 @@ public void Write(string s, Encoding encoding)
ThrowHelper.ThrowIfNull(s);
ThrowHelper.ThrowIfNull(encoding);

#if NETSTANDARD2_1 || NET
#if NET
ReadOnlySpan<char> value = s;
var count = encoding.GetByteCount(value);
var bytes = count <= 256 ? stackalloc byte[count] : new byte[count];
Expand Down Expand Up @@ -220,7 +220,7 @@ public void WriteBinary(byte[] buffer, int offset, int count)
/// </returns>
public BigInteger ReadBigInt()
{
#if NETSTANDARD2_1 || NET
#if NET
var data = ReadBinarySegment();
return new BigInteger(data, isBigEndian: true);
#else
Expand Down
6 changes: 3 additions & 3 deletions src/Renci.SshNet/Connection/ProxyConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ protected ProxyConnector(ISocketFactory socketFactory)

// ToDo: Performs async/sync fallback, true async version should be implemented in derived classes
protected virtual
#if NET || NETSTANDARD2_1
#if NET
async
#endif
Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

#if NET || NETSTANDARD2_1
#if NET
await using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false).ConfigureAwait(continueOnCapturedContext: false))
#else
using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false))
Expand All @@ -39,7 +39,7 @@ Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, Canc
#pragma warning restore MA0042 // Do not use blocking calls in an async method
}

#if !NET && !NETSTANDARD2_1
#if !NET
return Task.CompletedTask;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected override void LoadData()
PartialSuccess = ReadBoolean();
if (PartialSuccess)
{
#if NET || NETSTANDARD2_1
#if NET
Message = string.Join(',', AllowedAuthentications);
#else
Message = string.Join(",", AllowedAuthentications);
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Renci.SshNet</AssemblyName>
<Product>SSH.NET</Product>
<AssemblyTitle>SSH.NET</AssemblyTitle>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Renci.SshNet/ScpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ private string ReadString(Stream stream)
/// <param name="fileOrDirectory">The file or directory to upload.</param>
private void UploadTimes(IChannelSession channel, Stream input, FileSystemInfo fileOrDirectory)
{
#if NET || NETSTANDARD2_1
#if NET
var zeroTime = DateTime.UnixEpoch;
#else
var zeroTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
Expand Down Expand Up @@ -851,7 +851,7 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI
var mtime = long.Parse(match.Result("${mtime}"), CultureInfo.InvariantCulture);
var atime = long.Parse(match.Result("${atime}"), CultureInfo.InvariantCulture);

#if NET || NETSTANDARD2_1
#if NET
var zeroTime = DateTime.UnixEpoch;
#else
var zeroTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override BigInteger[] Public
Buffer.BlockCopy(qy, 0, q, qx.Length + 1, qy.Length);

// returns Curve-Name and x/y as ECPoint
#if NETSTANDARD2_1 || NET
#if NET
return new[] { curve, new BigInteger(q, isBigEndian: true) };
#else
Array.Reverse(q);
Expand Down
4 changes: 2 additions & 2 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ private Message ReceiveMessage(Socket socket)
if (_serverMac != null && _serverEtm)
{
var clientHash = _serverMac.ComputeHash(data, 0, data.Length - serverMacLength);
#if NETSTANDARD2_1 || NET
#if NET
if (!CryptographicOperations.FixedTimeEquals(clientHash, new ReadOnlySpan<byte>(data, data.Length - serverMacLength, serverMacLength)))
#else
if (!Org.BouncyCastle.Utilities.Arrays.FixedTimeEquals(serverMacLength, clientHash, 0, data, data.Length - serverMacLength))
Expand Down Expand Up @@ -1354,7 +1354,7 @@ private Message ReceiveMessage(Socket socket)
if (_serverMac != null && !_serverEtm)
{
var clientHash = _serverMac.ComputeHash(data, 0, data.Length - serverMacLength);
#if NETSTANDARD2_1 || NET
#if NET
if (!CryptographicOperations.FixedTimeEquals(clientHash, new ReadOnlySpan<byte>(data, data.Length - serverMacLength, serverMacLength)))
#else
if (!Org.BouncyCastle.Utilities.Arrays.FixedTimeEquals(serverMacLength, clientHash, 0, data, data.Length - serverMacLength))
Expand Down
8 changes: 4 additions & 4 deletions src/Renci.SshNet/Sftp/SftpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public string GetCanonicalPath(string path)
if (fullPath.EndsWith("/.", StringComparison.OrdinalIgnoreCase) ||
fullPath.EndsWith("/..", StringComparison.OrdinalIgnoreCase) ||
fullPath.Equals("/", StringComparison.OrdinalIgnoreCase) ||
#if NET || NETSTANDARD2_1
#if NET
fullPath.IndexOf('/', StringComparison.OrdinalIgnoreCase) < 0)
#else
fullPath.IndexOf('/') < 0)
Expand All @@ -146,7 +146,7 @@ public string GetCanonicalPath(string path)

var pathParts = fullPath.Split('/');

#if NET || NETSTANDARD2_1
#if NET
var partialFullPath = string.Join('/', pathParts, 0, pathParts.Length - 1);
#else
var partialFullPath = string.Join("/", pathParts, 0, pathParts.Length - 1);
Expand Down Expand Up @@ -206,7 +206,7 @@ public async Task<string> GetCanonicalPathAsync(string path, CancellationToken c
if (fullPath.EndsWith("/.", StringComparison.Ordinal) ||
fullPath.EndsWith("/..", StringComparison.Ordinal) ||
fullPath.Equals("/", StringComparison.Ordinal) ||
#if NET || NETSTANDARD2_1
#if NET
fullPath.IndexOf('/', StringComparison.Ordinal) < 0)
#else
fullPath.IndexOf('/') < 0)
Expand All @@ -217,7 +217,7 @@ public async Task<string> GetCanonicalPathAsync(string path, CancellationToken c

var pathParts = fullPath.Split('/');

#if NET || NETSTANDARD2_1
#if NET
var partialFullPath = string.Join('/', pathParts);
#else
var partialFullPath = string.Join("/", pathParts);
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/SftpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ private List<ISftpFile> InternalListDirectory(string path, SftpListDirectoryAsyn

var basePath = fullPath;

#if NET || NETSTANDARD2_1
#if NET
if (!basePath.EndsWith('/'))
#else
if (!basePath.EndsWith("/", StringComparison.Ordinal))
Expand Down
4 changes: 2 additions & 2 deletions src/Renci.SshNet/ShellStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ public override int Read(byte[] buffer, int offset, int count)
return Read(buffer.AsSpan(offset, count));
}

#if NETSTANDARD2_1 || NET
#if NET
/// <inheritdoc/>
public override int Read(Span<byte> buffer)
#else
Expand Down Expand Up @@ -838,7 +838,7 @@ public override void Write(byte[] buffer, int offset, int count)
Write(buffer.AsSpan(offset, count));
}

#if NETSTANDARD2_1 || NET
#if NET
/// <inheritdoc/>
public override void Write(ReadOnlySpan<byte> buffer)
#else
Expand Down
Loading