Procházet zdrojové kódy

Integrate with Nerdbank.GitVersioning (#1299)

* GeneratePackageOnBuild
IncludeSymbols

* Add packages to artifacts

* Update src/Renci.SshNet/Renci.SshNet.csproj

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Update Renci.SshNet.csproj

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* 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 <rob.hague00@gmail.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
Scott Xu před 1 rokem
rodič
revize
252c732c5e

+ 1 - 0
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}"

+ 9 - 1
src/Renci.SshNet/Renci.SshNet.csproj

@@ -11,7 +11,6 @@
     <IsPackable>true</IsPackable>
     <PackageId>SSH.NET</PackageId>
     <Title>SSH.NET</Title>
-    <Version>2024.1.0</Version>
     <Description>SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.</Description>
     <Copyright>Copyright © Renci 2010-$([System.DateTime]::UtcNow.Year)</Copyright>
     <PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -22,6 +21,7 @@
     <PackageReleaseNotes>https://github.com/sshnet/SSH.NET/releases/tag/$(Version)</PackageReleaseNotes>
     <IncludeSymbols>True</IncludeSymbols>
     <SymbolPackageFormat>snupkg</SymbolPackageFormat>
+    <NBGV_ThisAssemblyIncludesPackageVersion>true</NBGV_ThisAssemblyIncludesPackageVersion>
     <EmbedUntrackedSources>true</EmbedUntrackedSources>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
   </PropertyGroup>
@@ -33,6 +33,14 @@
   <PropertyGroup Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) ">
     <IsAotCompatible>true</IsAotCompatible>
   </PropertyGroup>
+  
+  <ItemGroup>
+    <!--
+    Any version which is 3.7.57-alpha or above, in order to pick up
+    https://github.com/dotnet/Nerdbank.GitVersioning/pull/1029.
+    -->
+    <PackageReference Include="Nerdbank.GitVersioning" Version="3.7.70-alpha" PrivateAssets="all" />
+  </ItemGroup>
 
   <ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">
     <!-- Must be kept at version 1.0.0 or higher, see https://github.com/sshnet/SSH.NET/pull/1288 for details. -->

+ 10 - 2
src/Renci.SshNet/Session.cs

@@ -31,6 +31,9 @@ namespace Renci.SshNet
         internal const byte CarriageReturn = 0x0d;
         internal const byte LineFeed = 0x0a;
 
+        private static readonly string ClientVersionString =
+            "SSH-2.0-Renci.SshNet.SshClient." + ThisAssembly.NuGetPackageVersion.Replace('-', '_');
+
         /// <summary>
         /// Specifies maximum packet size defined by the protocol.
         /// </summary>
@@ -313,7 +316,13 @@ namespace Renci.SshNet
         /// <value>
         /// The client version.
         /// </value>
-        public string ClientVersion { get; private set; }
+        public string ClientVersion
+        {
+            get
+            {
+                return ClientVersionString;
+            }
+        }
 
         /// <summary>
         /// Gets the connection info.
@@ -534,7 +543,6 @@ namespace Renci.SshNet
                 throw new ArgumentNullException(nameof(socketFactory));
             }
 
-            ClientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
             ConnectionInfo = connectionInfo;
             _serviceFactory = serviceFactory;
             _socketFactory = socketFactory;

+ 0 - 6
test/Renci.SshNet.Tests/Classes/SessionTest_ConnectToServerFails.cs

@@ -50,12 +50,6 @@ namespace Renci.SshNet.Tests.Classes
             }
         }
 
-        [TestMethod]
-        public void ClientVersionIsRenciSshNet()
-        {
-            Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion);
-        }
-
         [TestMethod]
         public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
         {

+ 5 - 1
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 @@ namespace Renci.SshNet.Tests.Classes
         [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]

+ 0 - 6
test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs

@@ -26,12 +26,6 @@ namespace Renci.SshNet.Tests.Classes
             _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()
         {

+ 14 - 0
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
+  }
+}