Skip to content

Commit

Permalink
Integrate with Nerdbank.GitVersioning (#1299)
Browse files Browse the repository at this point in the history
* GeneratePackageOnBuild
IncludeSymbols

* Add packages to artifacts

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

Co-authored-by: Rob Hague <[email protected]>

* Update Renci.SshNet.csproj

Co-authored-by: Rob Hague <[email protected]>

* 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 #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 <[email protected]>
Co-authored-by: Robert Hague <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2024
1 parent 486b69d commit 252c732
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions Renci.SshNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
10 changes: 9 additions & 1 deletion src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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. -->
Expand Down
12 changes: 10 additions & 2 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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('-', '_');

/// <summary>
/// Specifies maximum packet size defined by the protocol.
/// </summary>
Expand Down Expand Up @@ -313,7 +316,13 @@ public bool IsConnected
/// <value>
/// The client version.
/// </value>
public string ClientVersion { get; private set; }
public string ClientVersion
{
get
{
return ClientVersionString;
}
}

/// <summary>
/// Gets the connection info.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 5 additions & 1 deletion test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;

using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 0 additions & 6 deletions test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
14 changes: 14 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 252c732

Please sign in to comment.