From 252c732c5e4deeba55442b5a071ba86c578f6e68 Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Sat, 27 Jul 2024 15:45:41 +0800 Subject: [PATCH] Integrate with Nerdbank.GitVersioning (#1299) * GeneratePackageOnBuild IncludeSymbols * Add packages to artifacts * Update src/Renci.SshNet/Renci.SshNet.csproj Co-authored-by: Rob Hague * Update Renci.SshNet.csproj Co-authored-by: Rob Hague * Delete build/nuget/SSH.NET.nuspec * Delete SSH.NET.nuspec from .sln file * Update Renci.SshNet.csproj * Update build.proj * init nbgv * Include version.json in "Solution Items" * Update Directory.Build.props * define publicReleaseRefSpec * update version.json * update version.json * set cloud build number * fix https://github.com/sshnet/SSH.NET/issues/1292 * remove unexpected code format * Delete version from csproj * move nbgv from Directory.Build.props to Renci.SshNet.csproj as only this particular project needs versioning. include package version in ThisAssembly and use nuget package version for the SSH client version. Since we define the precision of nuget package to "build", it has 3 digits. Nuget package version is unique which should be suffient. * Use package from CI feed * Bump version to 2024.0.1; Update version precision * Some tweaks: - Remove the "release" section. I don't think we will use that for now - Remove the "cloudBuild" section. Changing the CI build number doesn't seem that useful - In the "nugetPackageVersion" section: - Remove "precision". It defaults to build - Add "semVer"=2. This makes the package version e.g. 2024.1.1-prerelease.1 instead of 2024.1.1-prerelease-0001 - In "assemblyVersion" change "precision" to revision. Doesn't seem to change anything, I was just copying nbgv's setup: https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/version.json - Make sure there are no '-' in the softwareversion string (change the test to a regex) * Revert unnecessary test changes; remove unnecessary tests --------- Co-authored-by: Rob Hague Co-authored-by: Robert Hague --- Renci.SshNet.sln | 1 + src/Renci.SshNet/Renci.SshNet.csproj | 10 +++++++++- src/Renci.SshNet/Session.cs | 12 ++++++++++-- .../Classes/SessionTest_ConnectToServerFails.cs | 6 ------ .../Classes/SessionTest_Connected.cs | 6 +++++- .../Classes/SessionTest_NotConnected.cs | 6 ------ version.json | 14 ++++++++++++++ 7 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 version.json 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 + } +}