Skip to content

Commit 252c732

Browse files
scott-xuRob-Hague
andauthored
Integrate with Nerdbank.GitVersioning (#1299)
* 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]>
1 parent 486b69d commit 252c732

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

Renci.SshNet.sln

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2020
README.md = README.md
2121
stylecop.json = stylecop.json
2222
THIRD-PARTY-NOTICES.TXT = THIRD-PARTY-NOTICES.TXT
23+
version.json = version.json
2324
EndProjectSection
2425
EndProject
2526
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D21A4D03-0AC2-4613-BB6D-74D2D16A72CC}"

src/Renci.SshNet/Renci.SshNet.csproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<IsPackable>true</IsPackable>
1212
<PackageId>SSH.NET</PackageId>
1313
<Title>SSH.NET</Title>
14-
<Version>2024.1.0</Version>
1514
<Description>SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.</Description>
1615
<Copyright>Copyright © Renci 2010-$([System.DateTime]::UtcNow.Year)</Copyright>
1716
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -22,6 +21,7 @@
2221
<PackageReleaseNotes>https://github.com/sshnet/SSH.NET/releases/tag/$(Version)</PackageReleaseNotes>
2322
<IncludeSymbols>True</IncludeSymbols>
2423
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
24+
<NBGV_ThisAssemblyIncludesPackageVersion>true</NBGV_ThisAssemblyIncludesPackageVersion>
2525
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2626
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2727
</PropertyGroup>
@@ -33,6 +33,14 @@
3333
<PropertyGroup Condition=" $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) ">
3434
<IsAotCompatible>true</IsAotCompatible>
3535
</PropertyGroup>
36+
37+
<ItemGroup>
38+
<!--
39+
Any version which is 3.7.57-alpha or above, in order to pick up
40+
https://github.com/dotnet/Nerdbank.GitVersioning/pull/1029.
41+
-->
42+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.70-alpha" PrivateAssets="all" />
43+
</ItemGroup>
3644

3745
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">
3846
<!-- Must be kept at version 1.0.0 or higher, see https://github.com/sshnet/SSH.NET/pull/1288 for details. -->

src/Renci.SshNet/Session.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class Session : ISession
3131
internal const byte CarriageReturn = 0x0d;
3232
internal const byte LineFeed = 0x0a;
3333

34+
private static readonly string ClientVersionString =
35+
"SSH-2.0-Renci.SshNet.SshClient." + ThisAssembly.NuGetPackageVersion.Replace('-', '_');
36+
3437
/// <summary>
3538
/// Specifies maximum packet size defined by the protocol.
3639
/// </summary>
@@ -313,7 +316,13 @@ public bool IsConnected
313316
/// <value>
314317
/// The client version.
315318
/// </value>
316-
public string ClientVersion { get; private set; }
319+
public string ClientVersion
320+
{
321+
get
322+
{
323+
return ClientVersionString;
324+
}
325+
}
317326

318327
/// <summary>
319328
/// Gets the connection info.
@@ -534,7 +543,6 @@ internal Session(ConnectionInfo connectionInfo, IServiceFactory serviceFactory,
534543
throw new ArgumentNullException(nameof(socketFactory));
535544
}
536545

537-
ClientVersion = "SSH-2.0-Renci.SshNet.SshClient.0.0.1";
538546
ConnectionInfo = connectionInfo;
539547
_serviceFactory = serviceFactory;
540548
_socketFactory = socketFactory;

test/Renci.SshNet.Tests/Classes/SessionTest_ConnectToServerFails.cs

-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ protected override void Act()
5050
}
5151
}
5252

53-
[TestMethod]
54-
public void ClientVersionIsRenciSshNet()
55-
{
56-
Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion);
57-
}
58-
5953
[TestMethod]
6054
public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
6155
{

test/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Text.RegularExpressions;
34
using System.Threading;
45

56
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -31,7 +32,10 @@ protected override void Act()
3132
[TestMethod]
3233
public void ClientVersionIsRenciSshNet()
3334
{
34-
Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", Session.ClientVersion);
35+
Assert.IsTrue(Regex.IsMatch(
36+
Session.ClientVersion,
37+
// Ends with e.g. 2024.1.1 plus some optional metadata not containing '-'
38+
@"^SSH-2\.0-Renci\.SshNet\.SshClient\.\d{4}\.\d+\.\d+(_[a-zA-Z0-9_\.]+)?$"));
3539
}
3640

3741
[TestMethod]

test/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs

-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ protected override void Act()
2626
_session = new Session(_connectionInfo, ServiceFactoryMock.Object, SocketFactoryMock.Object);
2727
}
2828

29-
[TestMethod]
30-
public void ClientVersionIsRenciSshNet()
31-
{
32-
Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion);
33-
}
34-
3529
[TestMethod]
3630
public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
3731
{

version.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
3+
"version": "2024.1.1-prerelease.{height}",
4+
"publicReleaseRefSpec": [
5+
"^refs/heads/develop$",
6+
"^refs/tags/\\d{4}\\.\\d+\\.\\d+"
7+
],
8+
"assemblyVersion": {
9+
"precision": "revision"
10+
},
11+
"nugetPackageVersion": {
12+
"semVer": 2
13+
}
14+
}

0 commit comments

Comments
 (0)