[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 227661e02c
PiperOrigin-RevId: 523196896
pull/12437/head
Romfos 2023-04-10 13:24:56 -07:00 committed by Copybara-Service
parent 5a679dfb29
commit 09f094c811
13 changed files with 48 additions and 46 deletions

View File

@ -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'

View File

@ -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

View File

@ -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)"],
)

View File

@ -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

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net451;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../keys/Google.Protobuf.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<IsPackable>False</IsPackable>
@ -18,9 +18,9 @@
<PackageReference Include="NUnitLite" Version="3.6.1" />
</ItemGroup>
<!-- Needed for the net45 build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
<!-- Needed for the netfx build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
</ItemGroup>
</Project>

View File

@ -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

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<StartupObject>Google.Protobuf.Examples.AddressBook.Program</StartupObject>
<IsPackable>False</IsPackable>

View File

@ -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__"],
)

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>False</IsPackable>
</PropertyGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>False</IsPackable>
</PropertyGroup>

View File

@ -6,14 +6,14 @@
and without the internal visibility from the test project (all of which have caused issues in the past).
-->
<PropertyGroup>
<TargetFrameworks>net462;netstandard1.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<AssemblyOriginatorKeyFile>../../keys/Google.Protobuf.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<IsPackable>False</IsPackable>
</PropertyGroup>
<!-- Needed for the net45 build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
<!-- Needed for the netfx build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
</ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;netcoreapp3.1;net60</TargetFrameworks>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../keys/Google.Protobuf.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<IsPackable>False</IsPackable>
@ -14,12 +14,12 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.2" />
</ItemGroup>
<!-- Needed for the net45 build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
<!-- Needed for the netfx build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="All" />
</ItemGroup>

View File

@ -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));
}
}
}
}