diff --git a/Renci.SshNet.sln b/Renci.SshNet.sln
index 56f818073..c03ba6c33 100644
--- a/Renci.SshNet.sln
+++ b/Renci.SshNet.sln
@@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
stylecop.json = stylecop.json
THIRD-PARTY-NOTICES.TXT = THIRD-PARTY-NOTICES.TXT
+ version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC}"
diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj
index 7634c3f81..bea1b66af 100644
--- a/src/Renci.SshNet/Renci.SshNet.csproj
+++ b/src/Renci.SshNet/Renci.SshNet.csproj
@@ -11,7 +11,6 @@
true
SSH.NET
SSH.NET
- 2024.1.0
SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
Copyright © Renci 2010-$([System.DateTime]::UtcNow.Year)
MIT
@@ -22,6 +21,7 @@
https://github.com/sshnet/SSH.NET/releases/tag/$(Version)
True
snupkg
+ true
true
true
@@ -33,6 +33,14 @@
true
+
+
+
+
+
diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs
index 64c20c64a..7ff95e27b 100644
--- a/src/Renci.SshNet/Session.cs
+++ b/src/Renci.SshNet/Session.cs
@@ -31,6 +31,9 @@ public class Session : ISession
internal const byte CarriageReturn = 0x0d;
internal const byte LineFeed = 0x0a;
+ private static readonly string ClientVersionString =
+ "SSH-2.0-Renci.SshNet.SshClient." + ThisAssembly.NuGetPackageVersion.Replace('-', '_');
+
///
/// Specifies maximum packet size defined by the protocol.
///
@@ -313,7 +316,13 @@ public bool IsConnected
///
/// The client version.
///
- public string ClientVersion { get; private set; }
+ public string ClientVersion
+ {
+ get
+ {
+ return ClientVersionString;
+ }
+ }
///
/// Gets the connection info.
@@ -534,7 +543,6 @@ internal Session(ConnectionInfo connectionInfo, IServiceFactory serviceFactory,
throw new ArgumentNullException(nameof(socketFactory));
}
- ClientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
ConnectionInfo = connectionInfo;
_serviceFactory = serviceFactory;
_socketFactory = socketFactory;
diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectToServerFails.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectToServerFails.cs
index 873275325..1b3f53dca 100644
--- a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectToServerFails.cs
+++ b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectToServerFails.cs
@@ -50,12 +50,6 @@ protected override void Act()
}
}
- [TestMethod]
- public void ClientVersionIsRenciSshNet()
- {
- Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion);
- }
-
[TestMethod]
public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
{
diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
index bebbe14ec..d105d9a35 100644
--- a/test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
+++ b/test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -31,7 +32,10 @@ protected override void Act()
[TestMethod]
public void ClientVersionIsRenciSshNet()
{
- Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", Session.ClientVersion);
+ Assert.IsTrue(Regex.IsMatch(
+ Session.ClientVersion,
+ // Ends with e.g. 2024.1.1 plus some optional metadata not containing '-'
+ @"^SSH-2\.0-Renci\.SshNet\.SshClient\.\d{4}\.\d+\.\d+(_[a-zA-Z0-9_\.]+)?$"));
}
[TestMethod]
diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs
index d54f9f4a3..f2f133bd0 100644
--- a/test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs
+++ b/test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs
@@ -26,12 +26,6 @@ protected override void Act()
_session = new Session(_connectionInfo, ServiceFactoryMock.Object, SocketFactoryMock.Object);
}
- [TestMethod]
- public void ClientVersionIsRenciSshNet()
- {
- Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion);
- }
-
[TestMethod]
public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
{
diff --git a/version.json b/version.json
new file mode 100644
index 000000000..f933e7fd9
--- /dev/null
+++ b/version.json
@@ -0,0 +1,14 @@
+{
+ "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
+ "version": "2024.1.1-prerelease.{height}",
+ "publicReleaseRefSpec": [
+ "^refs/heads/develop$",
+ "^refs/tags/\\d{4}\\.\\d+\\.\\d+"
+ ],
+ "assemblyVersion": {
+ "precision": "revision"
+ },
+ "nugetPackageVersion": {
+ "semVer": 2
+ }
+}