From 8790adefae322d2e6d680c8fb3470081bea0da0b Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Fri, 10 Jul 2020 09:12:26 +0200 Subject: [PATCH] Allow XmlSerializer.Generator to run on Core > 2.x (#39013) * Allow XmlSerializer.Generator to run on Core > 2.x * Use repo local dotnet toolchain to build Generator Use the repo local dotnet toolchain to generate the sgen output. Adding a test to verify that the repo local and the live built outputs are identical by size. --- ...Microsoft.XmlSerializer.Generator.runtimeconfig.json | 3 ++- .../Microsoft.XmlSerializer.Generator.Tests.csproj | 17 +++++++++++------ .../tests/SGenTests.cs | 10 ++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/libraries/Microsoft.XmlSerializer.Generator/pkg/build/dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json b/src/libraries/Microsoft.XmlSerializer.Generator/pkg/build/dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json index 7539019..a8e4102 100644 --- a/src/libraries/Microsoft.XmlSerializer.Generator/pkg/build/dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json +++ b/src/libraries/Microsoft.XmlSerializer.Generator/pkg/build/dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json @@ -4,6 +4,7 @@ "framework": { "name": "Microsoft.NETCore.App", "version": "2.0.0" - } + }, + "rollForward": "Major" } } \ No newline at end of file diff --git a/src/libraries/Microsoft.XmlSerializer.Generator/tests/Microsoft.XmlSerializer.Generator.Tests.csproj b/src/libraries/Microsoft.XmlSerializer.Generator/tests/Microsoft.XmlSerializer.Generator.Tests.csproj index 7cffe3c..7109d5b 100644 --- a/src/libraries/Microsoft.XmlSerializer.Generator/tests/Microsoft.XmlSerializer.Generator.Tests.csproj +++ b/src/libraries/Microsoft.XmlSerializer.Generator/tests/Microsoft.XmlSerializer.Generator.Tests.csproj @@ -4,27 +4,30 @@ $(NetCoreAppCurrent) true + - - $(MSBuildToolsPath)\MSBuild.runtimeconfig.json - "$(TestHostRootPath)$([System.IO.Path]::GetFileName('$(DotNetTool)'))" --fx-version $(ProductVersion) + $(MSBuildThisFileDirectory)..\pkg\build\dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json + "$(DotNetTool)" set DOTNET_MULTILEVEL_LOOKUP=0 & $(GeneratorCommand) export DOTNET_MULTILEVEL_LOOKUP=0 && $(GeneratorCommand) - - + + + + - + dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json PreserveNewest + @@ -41,6 +45,7 @@ + diff --git a/src/libraries/Microsoft.XmlSerializer.Generator/tests/SGenTests.cs b/src/libraries/Microsoft.XmlSerializer.Generator/tests/SGenTests.cs index ecd45eb..4b2fce4 100644 --- a/src/libraries/Microsoft.XmlSerializer.Generator/tests/SGenTests.cs +++ b/src/libraries/Microsoft.XmlSerializer.Generator/tests/SGenTests.cs @@ -15,13 +15,19 @@ namespace Microsoft.XmlSerializer.Generator.Tests [Fact] public static void SgenCommandTest() { - string codefile = "Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs"; + const string CodeFile = "Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs"; + const string LKGCodeFile = "LKG." + CodeFile; + var type = Type.GetType("Microsoft.XmlSerializer.Generator.Sgen, dotnet-Microsoft.XmlSerializer.Generator"); MethodInfo md = type.GetMethod("Main", BindingFlags.Static | BindingFlags.Public); string[] args = new string[] { "Microsoft.XmlSerializer.Generator.Tests.dll", "--force", "--quiet" }; int n = (int)md.Invoke(null, new object[] { args }); + Assert.Equal(0, n); - Assert.True(File.Exists(codefile), string.Format("Fail to generate {0}.", codefile)); + Assert.True(File.Exists(CodeFile), string.Format("Fail to generate {0}.", CodeFile)); + // Compare the generated CodeFiles from the LKG with the live built shared framework one. + // Not comparing byte per byte as the generated output isn't deterministic. + Assert.Equal(new System.IO.FileInfo(LKGCodeFile).Length, new System.IO.FileInfo(CodeFile).Length); } } } -- 2.7.4