From 1850ae303844957c6c4e4d7ae5d5e7530bf57a0b Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Thu, 18 Apr 2024 21:40:40 +0200 Subject: [PATCH 1/3] Add an AOT compatibility test app Following the guides at https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming?pivots=dotnet-8-0 and https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/, add an application which is published for AOT in CI. This process fully verifies all code-paths in the library and its dependencies for trimming/AOT, which the analyzers are not themselves able to do. (As a side benefit, now we are also checking the library builds in Release) --- Directory.Build.props | 1 + Renci.SshNet.sln | 22 +++++++++++++++++++ appveyor.yml | 1 + src/Renci.SshNet/Renci.SshNet.csproj | 5 ++--- .../Program.cs | 19 ++++++++++++++++ ...enci.SshNet.AotCompatibilityTestApp.csproj | 16 ++++++++++++++ .../Renci.SshNet.IntegrationTests.csproj | 1 - 7 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 test/Renci.SshNet.AotCompatibilityTestApp/Program.cs create mode 100644 test/Renci.SshNet.AotCompatibilityTestApp/Renci.SshNet.AotCompatibilityTestApp.csproj diff --git a/Directory.Build.props b/Directory.Build.props index b373ddf22..284b26d09 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,6 +5,7 @@ Assembly Info properties that apply to all projects/assemblies. --> + false true $(MSBuildThisFileDirectory)Renci.SshNet.snk true diff --git a/Renci.SshNet.sln b/Renci.SshNet.sln index 5c6c417ae..5d29e99ca 100644 --- a/Renci.SshNet.sln +++ b/Renci.SshNet.sln @@ -84,6 +84,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.Benchmarks", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.IntegrationBenchmarks", "test\Renci.SshNet.IntegrationBenchmarks\Renci.SshNet.IntegrationBenchmarks.csproj", "{6DFC1807-3F44-4302-A302-43F7D887C4E0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renci.SshNet.AotCompatibilityTestApp", "test\Renci.SshNet.AotCompatibilityTestApp\Renci.SshNet.AotCompatibilityTestApp.csproj", "{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -212,6 +214,26 @@ Global {6DFC1807-3F44-4302-A302-43F7D887C4E0}.Release|x64.Build.0 = Release|Any CPU {6DFC1807-3F44-4302-A302-43F7D887C4E0}.Release|x86.ActiveCfg = Release|Any CPU {6DFC1807-3F44-4302-A302-43F7D887C4E0}.Release|x86.Build.0 = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|ARM.ActiveCfg = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|ARM.Build.0 = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x64.ActiveCfg = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x64.Build.0 = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x86.ActiveCfg = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Debug|x86.Build.0 = Debug|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Any CPU.Build.0 = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|ARM.ActiveCfg = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|ARM.Build.0 = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x64.ActiveCfg = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x64.Build.0 = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x86.ActiveCfg = Release|Any CPU + {F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/appveyor.yml b/appveyor.yml index 6638609c1..53e5a05fb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,7 @@ for: build_script: - echo build - dotnet build Renci.SshNet.sln -c Debug + - dotnet publish -c Release -r win-x64 /warnaserror .\test\Renci.SshNet.AotCompatibilityTestApp\ test_script: - ps: echo "Run unit tests for .NET 8.0" diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index a6cf61884..00daaa85c 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -8,6 +8,7 @@ + true SSH.NET SSH.NET 2024.0.0 @@ -24,9 +25,7 @@ - true - true - true + true diff --git a/test/Renci.SshNet.AotCompatibilityTestApp/Program.cs b/test/Renci.SshNet.AotCompatibilityTestApp/Program.cs new file mode 100644 index 000000000..a85c7ceda --- /dev/null +++ b/test/Renci.SshNet.AotCompatibilityTestApp/Program.cs @@ -0,0 +1,19 @@ +using System; + +namespace Renci.SshNet.AotCompatibilityTestApp +{ + public static class Program + { + public static void Main() + { + // This app is used to verify the trim- and AOT-friendliness of + // the library and its dependencies, by specifying + // in the csproj and publishing with e.g. "dotnet publish -c Release -r win-x64" + + // See https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming?pivots=dotnet-8-0 + // and https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/ + + Console.WriteLine("Hello, AOT!"); + } + } +} diff --git a/test/Renci.SshNet.AotCompatibilityTestApp/Renci.SshNet.AotCompatibilityTestApp.csproj b/test/Renci.SshNet.AotCompatibilityTestApp/Renci.SshNet.AotCompatibilityTestApp.csproj new file mode 100644 index 000000000..bf4fdbc82 --- /dev/null +++ b/test/Renci.SshNet.AotCompatibilityTestApp/Renci.SshNet.AotCompatibilityTestApp.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + true + true + false + + + + + + + + diff --git a/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj b/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj index 86e4cb0e6..f97567b9a 100644 --- a/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj +++ b/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj @@ -3,7 +3,6 @@ net48;net8.0 enable - false true $(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010 true From 6ff943b5024b9ef57f94feb466dabeb55257fe2e Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Thu, 18 Apr 2024 22:06:16 +0200 Subject: [PATCH 2/3] Test failure scenario --- src/Renci.SshNet/Renci.SshNet.csproj | 6 +++++- src/Renci.SshNet/SshCommand.cs | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 00daaa85c..585eb4605 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -30,7 +30,7 @@ - + @@ -44,4 +44,8 @@ + + + + diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs index df61cda7e..deaddd18a 100644 --- a/src/Renci.SshNet/SshCommand.cs +++ b/src/Renci.SshNet/SshCommand.cs @@ -5,9 +5,12 @@ using System.Text; using System.Threading; +using CsvHelper; + using Renci.SshNet.Abstractions; using Renci.SshNet.Channels; using Renci.SshNet.Common; +using Renci.SshNet.Messages; using Renci.SshNet.Messages.Connection; using Renci.SshNet.Messages.Transport; @@ -118,8 +121,12 @@ public string Result detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true)) + using (var csv = new CsvReader(sr, CultureInfo.InvariantCulture)) { - _ = _result.Append(sr.ReadToEnd()); + foreach (var m in csv.GetRecords()) + { + _ = _result.Append(m); + } } } From 160dfb32f906c23dedee95034ea3af87488316cf Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Thu, 18 Apr 2024 22:32:51 +0200 Subject: [PATCH 3/3] Revert "Test failure scenario" This reverts commit 6ff943b5024b9ef57f94feb466dabeb55257fe2e. --- src/Renci.SshNet/Renci.SshNet.csproj | 6 +----- src/Renci.SshNet/SshCommand.cs | 9 +-------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 585eb4605..00daaa85c 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -30,7 +30,7 @@ - + @@ -44,8 +44,4 @@ - - - - diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs index deaddd18a..df61cda7e 100644 --- a/src/Renci.SshNet/SshCommand.cs +++ b/src/Renci.SshNet/SshCommand.cs @@ -5,12 +5,9 @@ using System.Text; using System.Threading; -using CsvHelper; - using Renci.SshNet.Abstractions; using Renci.SshNet.Channels; using Renci.SshNet.Common; -using Renci.SshNet.Messages; using Renci.SshNet.Messages.Connection; using Renci.SshNet.Messages.Transport; @@ -121,12 +118,8 @@ public string Result detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true)) - using (var csv = new CsvReader(sr, CultureInfo.InvariantCulture)) { - foreach (var m in csv.GetRecords()) - { - _ = _result.Append(m); - } + _ = _result.Append(sr.ReadToEnd()); } }