From 09f094c81178caf3169e83e989b5d8e0c3c2ffa2 Mon Sep 17 00:00:00 2001 From: Romfos Date: Mon, 10 Apr 2023 13:24:56 -0700 Subject: [PATCH] [dotnet, csharp] Run tests for supported platforms .NET 6, .NET Framework 4.6.2 (#12378) What's changed? - Update some nuget packages (for test projects) - Run unit tests for supported platforms: .NET 6 + .NET Framework 4.6.2 Notes: .NET Framework 4.6.1 is out of support, .NET Framework 4.6.2 is the older version that is still supported https://devblogs.microsoft.com/dotnet/net-framework-4-5-2-4-6-4-6-1-will-reach-end-of-support-on-april-26-2022/ .NET 5 is out of support https://devblogs.microsoft.com/dotnet/dotnet-5-end-of-support-update/ .NET Core 3.1 is out of support https://devblogs.microsoft.com/dotnet/net-core-3-1-will-reach-end-of-support-on-december-13-2022/ Visual studio 2012 is out of support https://devblogs.microsoft.com/visualstudio/support-ends-for-older-versions-of-visual-studio-feb2022 Closes #12378 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/12378 from Romfos:main 227661e02cc47673295a5d0e03763f8e2bf0f124 PiperOrigin-RevId: 523196896 --- .github/workflows/test_csharp.yml | 4 +-- appveyor.bat | 4 +-- csharp/BUILD.bazel | 34 ++++++++++--------- csharp/buildall.sh | 4 +-- .../Google.Protobuf.Test.csproj | 6 ++-- csharp/compatibility_tests/v3.0.0/test.sh | 2 +- csharp/src/AddressBook/AddressBook.csproj | 2 +- .../Google.Protobuf.Conformance/BUILD.bazel | 10 +++--- .../Google.Protobuf.Conformance.csproj | 2 +- .../Google.Protobuf.JsonDump.csproj | 2 +- .../Google.Protobuf.Test.TestProtos.csproj | 4 +-- .../Google.Protobuf.Test.csproj | 8 ++--- .../src/Google.Protobuf/WritingPrimitives.cs | 12 ++++--- 13 files changed, 48 insertions(+), 46 deletions(-) diff --git a/.github/workflows/test_csharp.yml b/.github/workflows/test_csharp.yml index c9e651eaf2..cc729ed0d5 100644 --- a/.github/workflows/test_csharp.yml +++ b/.github/workflows/test_csharp.yml @@ -65,7 +65,7 @@ jobs: /bin/bash -c ' DOTNET_CLI_TELEMETRY_OPTOUT=true DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true - dotnet publish -c Release -f net60 /workspace/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj' + dotnet publish -c Release -f net6.0 /workspace/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj' - name: Use an actual aarch64 docker image to run protobuf C# tests with an emulator # "dotnet vstest" allows running tests from a pre-built project. @@ -83,4 +83,4 @@ jobs: /bin/bash -c ' DOTNET_CLI_TELEMETRY_OPTOUT=true DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true - dotnet vstest /workspace/csharp/src/Google.Protobuf.Test/bin/Release/net60/publish/Google.Protobuf.Test.dll' + dotnet vstest /workspace/csharp/src/Google.Protobuf.Test/bin/Release/net6.0/publish/Google.Protobuf.Test.dll' diff --git a/appveyor.bat b/appveyor.bat index 005fb11f89..c8c51990e2 100644 --- a/appveyor.bat +++ b/appveyor.bat @@ -38,8 +38,8 @@ dotnet restore dotnet build -c %configuration% || goto error echo Testing C# -dotnet test -c %configuration% -f netcoreapp3.1 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error -dotnet test -c %configuration% -f net451 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error +dotnet test -c %configuration% -f net6.0 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error +dotnet test -c %configuration% -f net462 Google.Protobuf.Test\Google.Protobuf.Test.csproj || goto error goto :EOF diff --git a/csharp/BUILD.bazel b/csharp/BUILD.bazel index 2af7d067af..481a492cc9 100644 --- a/csharp/BUILD.bazel +++ b/csharp/BUILD.bazel @@ -3,7 +3,6 @@ # See also code generation logic under /src/google/protobuf/compiler/csharp. load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//:protobuf.bzl", "internal_csharp_proto_library") load("//build_defs:internal_shell.bzl", "inline_sh_test") load("//conformance:defs.bzl", "conformance_test") @@ -24,21 +23,24 @@ conformance_test( filegroup( name = "srcs", - srcs = glob([ - "keys/*", - "protos/*", - "src/**/*.cs*", # .cs and .csproj - ], exclude = [ - # Exclude generated files. - "src/*/obj/**/*" - ]) + [ + srcs = glob( + [ + "keys/*", + "protos/*", + "src/**/*.cs*", # .cs and .csproj + ], + exclude = [ + # Exclude generated files. + "src/*/obj/**/*", + ], + ) + [ "src/Directory.Build.props", "src/Google.Protobuf.Test/testprotos.pb", "src/Google.Protobuf.sln", ], visibility = [ + "//conformance:__subpackages__", "//csharp:__subpackages__", - "//conformance:__subpackages__" ], ) @@ -63,8 +65,8 @@ filegroup( inline_sh_test( name = "tests", srcs = [ - ":srcs", "src/Google.Protobuf.sln", + ":srcs", "//conformance:conformance_csharp_proto", "//csharp/src/Google.Protobuf.Conformance:srcs", ], @@ -73,7 +75,7 @@ inline_sh_test( pushd `dirname $(location src/Google.Protobuf.sln)`/.. dotnet restore src/Google.Protobuf.sln dotnet build -c Release src/Google.Protobuf.sln - dotnet test -c Release -f netcoreapp3.1 src/Google.Protobuf.Test/Google.Protobuf.Test.csproj + dotnet test -c Release -f net6.0 src/Google.Protobuf.Test/Google.Protobuf.Test.csproj popd """, ) @@ -85,7 +87,6 @@ inline_sh_test( pkg_files( name = "dist_files", srcs = [ - ":srcs", ".editorconfig", ".gitignore", "BUILD.bazel", @@ -101,6 +102,7 @@ pkg_files( "buildall.sh", "generate_protos.sh", "install_dotnet_sdk.ps1", + ":srcs", "//csharp/src/Google.Protobuf.Conformance:dist_files", ], strip_prefix = strip_prefix.from_root(""), @@ -108,7 +110,7 @@ pkg_files( ) sh_binary( - name = "release", - srcs = ["build_release.sh"], - args = ["$(location build_release.sh)"], + name = "release", + srcs = ["build_release.sh"], + args = ["$(location build_release.sh)"], ) diff --git a/csharp/buildall.sh b/csharp/buildall.sh index ab1a6c425a..c9525eb0e9 100755 --- a/csharp/buildall.sh +++ b/csharp/buildall.sh @@ -10,8 +10,8 @@ dotnet restore $SRC/Google.Protobuf.sln dotnet build -c $CONFIG $SRC/Google.Protobuf.sln echo Running tests. -# Only test netcoreapp3.1, which uses the .NET Core runtime. +# Only test net6.0, which uses the .NET runtime. # If we want to test the .NET 4.5 version separately, we could # run Mono explicitly. However, we don't have any differences between # the .NET 4.5 and netstandard2.1 assemblies. -dotnet test -c $CONFIG -f netcoreapp3.1 $SRC/Google.Protobuf.Test/Google.Protobuf.Test.csproj +dotnet test -c $CONFIG -f net6.0 $SRC/Google.Protobuf.Test/Google.Protobuf.Test.csproj diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index a2d501a81a..59edf2c24c 100644 --- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -2,7 +2,7 @@ Exe - net451;netcoreapp3.1 + net462;net6.0 ../../keys/Google.Protobuf.snk true False @@ -18,9 +18,9 @@ - + - + diff --git a/csharp/compatibility_tests/v3.0.0/test.sh b/csharp/compatibility_tests/v3.0.0/test.sh index 6323a6d076..ddf844a4f5 100755 --- a/csharp/compatibility_tests/v3.0.0/test.sh +++ b/csharp/compatibility_tests/v3.0.0/test.sh @@ -22,7 +22,7 @@ function run_test() { dotnet restore src/Google.Protobuf.Test/Google.Protobuf.Test.csproj dotnet build -c Release src/Google.Protobuf/Google.Protobuf.csproj dotnet build -c Release src/Google.Protobuf.Test/Google.Protobuf.Test.csproj - dotnet run -c Release -f netcoreapp3.1 -p src/Google.Protobuf.Test/Google.Protobuf.Test.csproj + dotnet run -c Release -f net6.0 -p src/Google.Protobuf.Test/Google.Protobuf.Test.csproj } set -ex diff --git a/csharp/src/AddressBook/AddressBook.csproj b/csharp/src/AddressBook/AddressBook.csproj index 9a527874ce..a50fc47033 100644 --- a/csharp/src/AddressBook/AddressBook.csproj +++ b/csharp/src/AddressBook/AddressBook.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 Exe Google.Protobuf.Examples.AddressBook.Program False diff --git a/csharp/src/Google.Protobuf.Conformance/BUILD.bazel b/csharp/src/Google.Protobuf.Conformance/BUILD.bazel index 0b5e2c8f83..df7371f662 100644 --- a/csharp/src/Google.Protobuf.Conformance/BUILD.bazel +++ b/csharp/src/Google.Protobuf.Conformance/BUILD.bazel @@ -1,4 +1,3 @@ -load("//:protobuf.bzl", "internal_csharp_proto_library") load("//build_defs:internal_shell.bzl", "inline_sh_binary") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") @@ -38,8 +37,8 @@ CONFORMANCE_DEPS = [ filegroup( name = "srcs", srcs = [ - "Program.cs", "Google.Protobuf.Conformance.csproj", + "Program.cs", ], visibility = [ "//csharp:__subpackages__", @@ -54,15 +53,15 @@ genrule( "//conformance:conformance_csharp_proto", "//csharp:srcs", ], - visibility = ["//visibility:private"], - tools = [":build_conformance_test"], outs = CONFORMANCE_DEPS + ["Google.Protobuf.Conformance.dll"], cmd = """ SRCDIR=$$(dirname $(location :Program.cs)) cp $(location //conformance:conformance_csharp_proto) $$SRCDIR DOTNET_CLI_HOME=/tmp ./$(location :build_conformance_test) - cp -r $$SRCDIR/bin/Release/netcoreapp3.1/* $(RULEDIR) + cp -r $$SRCDIR/bin/Release/net6.0/* $(RULEDIR) """, + tools = [":build_conformance_test"], + visibility = ["//visibility:private"], ) filegroup( @@ -93,4 +92,3 @@ pkg_files( strip_prefix = strip_prefix.from_root(""), visibility = ["//csharp:__pkg__"], ) - diff --git a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj index 6277e6898a..3bcfb35426 100644 --- a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj +++ b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 Exe False diff --git a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj index b2c4272628..475402b98f 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj +++ b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 Exe False diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj b/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj index 3d0ba71752..1d21193dd4 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj @@ -6,14 +6,14 @@ and without the internal visibility from the test project (all of which have caused issues in the past). --> - net462;netstandard1.1;netstandard2.0 + net462;netstandard2.0 10.0 ../../keys/Google.Protobuf.snk true False - + diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index fe5ff80467..1c5e576b6d 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -1,7 +1,7 @@  - net462;netcoreapp3.1;net60 + net462;net6.0 ../../keys/Google.Protobuf.snk true False @@ -14,12 +14,12 @@ - + - + - + diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs index cfba5c7288..4007f5ae1c 100644 --- a/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ @@ -50,10 +50,12 @@ namespace Google.Protobuf [SecuritySafeCritical] internal static class WritingPrimitives { -#if NET5_0 - internal static Encoding Utf8Encoding => Encoding.UTF8; // allows JIT to devirtualize +#if NET5_0_OR_GREATER + internal static Encoding Utf8Encoding => Encoding.UTF8; // allows JIT to devirtualize #else - internal static readonly Encoding Utf8Encoding = Encoding.UTF8; // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.) + internal static readonly Encoding Utf8Encoding = + Encoding.UTF8; // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a + // difference.) #endif #region Writing of values (not including tags) @@ -753,4 +755,4 @@ namespace Google.Protobuf return (ulong)((n << 1) ^ (n >> 63)); } } -} \ No newline at end of file +}