From a3979d5f7cddf92494ca74960c134615e98abdde Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 5 Aug 2020 12:27:39 -0500 Subject: [PATCH] [tests, build] multi-target Xamarin.Android.Build.Tests There are various tests in `Xamarin.Android.Build.Tests` that execute MSBuild tasks directly. This means the changes in #4820 are not quite complete. We need to actually *run* the tests under .NET Core to see if these tests would pass under a One .NET context. The solution (you would think), would be to make the test assembly `netstandard2.0` so you could run either: > nunit3-console Xamarin.Android.Build.Tests.dll > dotnet test Xamarin.Android.Build.Tests.dll `nunit3-console` would execute the tests under .NET framework/Mono and `dotnet test` would run under .NET Core or .NET 5+. Unfortunately, `nunit3-console` can't run tests from a `netstandard2.0` library! So we multi-target: net472;net5.0 Unfortunately, the `net5.0` causes MSBuild to fail with: > msbuild Xamarin.Android.sln ... (GetReferenceAssemblyPaths target) -> C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks I think there is some expectation to use `dotnet build` for .NET 5 instead. We don't want to move our *entire* build over to `dotnet build` yet (we probably can't!), so instead we can do: net472;netcoreapp3.1 This allows `msbuild Xamarin.Android.sln` to continue to work. This might also be something that gets fixed in a future MSBuild version. I updated various `.yaml` definitions so we can run NUnit tests via `nunit3-console` or `dotnet test` as needed. Other things that broke here: * We need `Microsoft.NET.Test.Sdk` for `dotnet test` to work. * `Builder.UseDotNet` can now be set based on a `#if` instead of an NUnit parameter. * `Xamarin.Android.Tools.Aidl` needs to be `netstandard2.0`. This required including a `System.CodeDom` package. * `Xamarin.Android.Build.Tasks` can't use `FSharp.Core` in `netcoreapp3.1`. I just removed it, since it is not used. * Updated various paths to `Xamarin.Android.Build.Tests.dll`. * Usage of System.Drawing crashed on macOS. I replaced this with ImageSharp: https://www.nuget.org/packages/SixLabors.ImageSharp/ --- .vscode/launch.json | 2 +- .vscode/settings.json | 2 +- build-tools/automation/azure-pipelines.yaml | 16 ++++---- .../yaml-templates/run-msbuild-mac-tests.yaml | 15 +++++-- .../yaml-templates/run-msbuild-win-tests.yaml | 14 +++++-- .../yaml-templates/run-nunit-tests.yaml | 12 ++++-- .../installers/create-installers.targets | 2 +- build-tools/scripts/RunTests.targets | 2 +- .../BindingBuildTest.cs | 4 +- .../Tasks/ManagedResourceParserTests.cs | 1 + .../Tasks/ResolveSdksTaskTests.cs | 2 +- .../Utilities/BaseTest.cs | 6 ++- .../Xamarin.Android.Build.Tests.csproj | 12 +++++- .../Android/XamarinAndroidCommonProject.cs | 34 ++++++---------- .../Xamarin.ProjectTools.csproj | 2 +- .../Xamarin.Android.Build.Tasks.csproj | 1 - .../Xamarin.Android.Build.Tasks.targets | 1 - .../Xamarin.Android.Tools.Aidl.csproj | 40 +++---------------- 18 files changed, 80 insertions(+), 88 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 30eeab2d279..d34884263e6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Launch", "type": "mono", "request": "launch", - "program": "${workspaceRoot}packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe ${workspaceRoot}bin/TestDebug/Xamarin.Android.Build.Tests.dll", + "program": "${workspaceRoot}packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe ${workspaceRoot}bin/TestDebug/net472/Xamarin.Android.Build.Tests.dll", "cwd": "${workspaceRoot}bin/TestDebug/" }, { diff --git a/.vscode/settings.json b/.vscode/settings.json index 0d0f9e6748c..551d332b1b5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "nxunitExplorer.nunit": "packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe", "nxunitExplorer.modules": [ "bin/TestDebug/MSBuildDeviceIntegration/MSBuildDeviceIntegration.dll", - "bin/TestDebug/Xamarin.Android.Build.Tests.dll", + "bin/TestDebug/net472/Xamarin.Android.Build.Tests.dll", "bin/TestDebug/Xamarin.Android.Build.Tests.Commercial.dll", ], "cmake.configureOnOpen": false diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index e79384252d2..a9fceb70d05 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -63,7 +63,7 @@ variables: # - This is a non-fork branch with name containing "mono-" (for Mono bumps) IsMonoBranch: $[and(eq(variables['XA.Commercial.Build'], 'true'), ne(variables['System.PullRequest.IsFork'], 'True'), or(contains(variables['Build.SourceBranchName'], 'mono-'), contains(variables['System.PullRequest.SourceBranch'], 'mono-')))] RunAllTests: $[or(eq(variables['XA.RunAllTests'], true), eq(variables['IsMonoBranch'], true))] - DotNetNUnitCategories: '&& cat != DotNetIgnore && cat != AOT && cat != FSharp && cat != LibraryProjectZip && cat != MkBundle && cat != MonoSymbolicate && cat != PackagesConfig && cat != StaticProject' + DotNetNUnitCategories: '& TestCategory != DotNetIgnore & TestCategory != AOT & TestCategory != FSharp & TestCategory != LibraryProjectZip & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject' # Stage and Job "display names" are shortened because they are combined to form the name of the corresponding GitHub check. stages: @@ -366,7 +366,7 @@ stages: - template: yaml-templates\run-nunit-tests.yaml parameters: testRunTitle: Smoke MSBuild Tests - Windows Build Tree - testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\Xamarin.Android.Build.Tests.dll + testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\net472\Xamarin.Android.Build.Tests.dll testResultsFile: TestResult-SmokeMSBuildTests-WinBuildTree-$(XA.Build.Configuration).xml nunitConsoleExtraArgs: --where "cat == SmokeTests" --workers=4 @@ -1054,7 +1054,7 @@ stages: job_name: mac_dotnet_tests_1 job_suffix: One .NET nunit_categories: $(DotNetNUnitCategories) - nunit_extra: --testparam dotnet=true + target_framework: 'netcoreapp3.1' - template: yaml-templates\run-msbuild-mac-tests.yaml parameters: @@ -1062,7 +1062,7 @@ stages: job_name: mac_dotnet_tests_2 job_suffix: One .NET nunit_categories: $(DotNetNUnitCategories) - nunit_extra: --testparam dotnet=true + target_framework: 'netcoreapp3.1' - template: yaml-templates\run-msbuild-mac-tests.yaml parameters: @@ -1070,7 +1070,7 @@ stages: job_name: mac_dotnet_tests_3 job_suffix: One .NET nunit_categories: $(DotNetNUnitCategories) - nunit_extra: --testparam dotnet=true + target_framework: 'netcoreapp3.1' # Xamarin.Android (Test MSBuild - Windows - One .NET) - template: yaml-templates\run-msbuild-win-tests.yaml @@ -1079,7 +1079,7 @@ stages: job_name: win_dotnet_tests_1 job_suffix: One .NET nunit_categories: $(DotNetNUnitCategories) - nunit_extra: --testparam dotnet=true + target_framework: 'netcoreapp3.1' - template: yaml-templates\run-msbuild-win-tests.yaml parameters: @@ -1087,7 +1087,7 @@ stages: job_name: win_dotnet_tests_2 job_suffix: One .NET nunit_categories: $(DotNetNUnitCategories) - nunit_extra: --testparam dotnet=true + target_framework: 'netcoreapp3.1' - template: yaml-templates\run-msbuild-win-tests.yaml parameters: @@ -1095,7 +1095,7 @@ stages: job_name: win_dotnet_tests_3 job_suffix: One .NET nunit_categories: $(DotNetNUnitCategories) - nunit_extra: --testparam dotnet=true + target_framework: 'netcoreapp3.1' - stage: integrated_regression_test displayName: Regression Tests diff --git a/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml b/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml index a68366b1ffa..c67c8f1d409 100644 --- a/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml +++ b/build-tools/automation/yaml-templates/run-msbuild-mac-tests.yaml @@ -5,7 +5,7 @@ parameters: job_name: '' job_suffix: '' nunit_categories: '' - nunit_extra: '' + target_framework: 'net472' run_extra_tests: false jobs: @@ -16,6 +16,8 @@ jobs: cancelTimeoutInMinutes: 5 workspace: clean: all + variables: + UseDotNet: ${{ eq(parameters.target_framework, 'netcoreapp3.1') }} steps: - template: setup-test-environment.yaml @@ -31,24 +33,29 @@ jobs: - template: run-nunit-tests.yaml parameters: + useDotNet: $(UseDotNet) testRunTitle: Xamarin.Android.Build.Tests - macOS-${{ parameters.node_id }} - ${{ parameters.job_suffix }} - testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/Xamarin.Android.Build.Tests.dll - nunitConsoleExtraArgs: --where "cat == Node-${{ parameters.node_id }} ${{ parameters.nunit_categories }}" ${{ parameters.nunit_extra }} + testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/${{ parameters.target_framework }}/Xamarin.Android.Build.Tests.dll + nunitConsoleExtraArgs: --where "cat == Node-${{ parameters.node_id }} ${{ parameters.nunit_categories }}" + dotNetTestExtraArgs: --filter "TestCategory = Node-${{ parameters.node_id }} ${{ parameters.nunit_categories }}" testResultsFile: TestResult-MSBuildTests-${{ parameters.job_name }}-$(XA.Build.Configuration).xml # Only run these tests on node 2 - ${{ if eq(parameters.run_extra_tests, true) }}: - template: run-nunit-tests.yaml parameters: + useDotNet: $(UseDotNet) testRunTitle: Xamarin.Android.Build.Tests.Commercial - macOS testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/Xamarin.Android.Build.Tests.Commercial.dll testResultsFile: TestResult-MSBuildTestsCommercial-macOS-$(XA.Build.Configuration).xml - template: run-nunit-tests.yaml parameters: + useDotNet: $(UseDotNet) testRunTitle: Xamarin.Android.Build.Tests - macOS - No Node - testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/Xamarin.Android.Build.Tests.dll + testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/${{ parameters.target_framework }}/Xamarin.Android.Build.Tests.dll nunitConsoleExtraArgs: --where "cat != Node-1 && cat != Node-2 && cat != Node-3" + dotNetTestExtraArgs: --filter "TestCategory != Node-1 & TestCategory != Node-2 & TestCategory != Node-3" testResultsFile: TestResult-MSBuildTests-macOS-NoNode-$(XA.Build.Configuration).xml - template: upload-results.yaml diff --git a/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml b/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml index ec547c801ce..378d8ad5c98 100644 --- a/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml +++ b/build-tools/automation/yaml-templates/run-msbuild-win-tests.yaml @@ -5,7 +5,7 @@ parameters: job_name: '' job_suffix: '' nunit_categories: '' - nunit_extra: '' + target_framework: 'net472' run_extra_tests: false jobs: @@ -16,6 +16,7 @@ jobs: cancelTimeoutInMinutes: 5 variables: VSINSTALLDIR: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise + UseDotNet: ${{ eq(parameters.target_framework, 'netcoreapp3.1') }} steps: - template: kill-processes.yaml @@ -42,24 +43,29 @@ jobs: # Using all available cores seems to occasionally bog down our machines and cause parallel test execution to slow down dramatically. - template: run-nunit-tests.yaml parameters: + useDotNet: $(UseDotNet) testRunTitle: Xamarin.Android.Build.Tests - Windows-${{ parameters.node_id }} - ${{ parameters.job_suffix }} - testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\Xamarin.Android.Build.Tests.dll - nunitConsoleExtraArgs: --workers=4 --where "cat == Node-${{ parameters.node_id }} ${{ parameters.nunit_categories }}" ${{ parameters.nunit_extra }} + testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\${{ parameters.target_framework }}\Xamarin.Android.Build.Tests.dll + nunitConsoleExtraArgs: --workers=4 --where "cat == Node-${{ parameters.node_id }} ${{ parameters.nunit_categories }}" + dotNetTestExtraArgs: --filter "TestCategory = Node-${{ parameters.node_id }} ${{ parameters.nunit_categories }}" testResultsFile: TestResult-MSBuildTests-${{ parameters.job_name }}-$(XA.Build.Configuration).xml # Only run these tests on node 2 - ${{ if eq(parameters.run_extra_tests, true) }}: - template: run-nunit-tests.yaml parameters: + useDotNet: $(UseDotNet) testRunTitle: Xamarin.Android.Build.Tests.Commercial - Windows testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\Xamarin.Android.Build.Tests.Commercial.dll testResultsFile: TestResult-MSBuildTestsCommercial-Windows-$(XA.Build.Configuration).xml - template: run-nunit-tests.yaml parameters: + useDotNet: $(UseDotNet) testRunTitle: Xamarin.Android.Build.Tests - Windows - No Node - testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\Xamarin.Android.Build.Tests.dll + testAssembly: $(System.DefaultWorkingDirectory)\bin\Test$(XA.Build.Configuration)\${{ parameters.target_framework }}\Xamarin.Android.Build.Tests.dll nunitConsoleExtraArgs: --workers=4 --where "cat != Node-1 && cat != Node-2 && cat != Node-3" + dotNetTestExtraArgs: --filter "TestCategory != Node-1 & TestCategory != Node-2 & TestCategory != Node-3" testResultsFile: TestResult-MSBuildTests-Windows-NoNode-$(XA.Build.Configuration).xml - template: upload-results.yaml diff --git a/build-tools/automation/yaml-templates/run-nunit-tests.yaml b/build-tools/automation/yaml-templates/run-nunit-tests.yaml index beda4b12131..06f04be8138 100644 --- a/build-tools/automation/yaml-templates/run-nunit-tests.yaml +++ b/build-tools/automation/yaml-templates/run-nunit-tests.yaml @@ -3,15 +3,21 @@ parameters: testRunTitle: Xamarin Android Tests testAssembly: [] testResultsFile: TestResult.xml - testResultsFormat: NUnit nunitConsoleExtraArgs: '' + dotNetTestExtraArgs: '' + useDotNet: false condition: succeeded() steps: - powershell: | - if ([Environment]::OSVersion.Platform -eq "Unix") { + if ("${{ parameters.useDotNet }}" -eq $true) { + Write-Host '##vso[task.setvariable variable=TestResultsFormat]VSTest' + dotnet test ${{ parameters.testAssembly }} --results-directory . --logger "trx;LogFileName=${{ parameters.testResultsFile }}" ${{ parameters.dotNetTestExtraArgs }} + } elseif ([Environment]::OSVersion.Platform -eq "Unix") { + Write-Host '##vso[task.setvariable variable=TestResultsFormat]NUnit' mono ${{ parameters.nunitConsole }} ${{ parameters.testAssembly }} --result ${{ parameters.testResultsFile }} ${{ parameters.nunitConsoleExtraArgs }} } else { + Write-Host '##vso[task.setvariable variable=TestResultsFormat]NUnit' ${{ parameters.nunitConsole }} ${{ parameters.testAssembly }} --result ${{ parameters.testResultsFile }} ${{ parameters.nunitConsoleExtraArgs }} } if ($LASTEXITCODE -ne 0) { @@ -27,7 +33,7 @@ steps: - task: PublishTestResults@2 inputs: - testResultsFormat: ${{ parameters.testResultsFormat }} + testResultsFormat: $(TestResultsFormat) testResultsFiles: ${{ parameters.testResultsFile }} testRunTitle: ${{ parameters.testRunTitle }} condition: ${{ parameters.condition }} diff --git a/build-tools/installers/create-installers.targets b/build-tools/installers/create-installers.targets index e5abae9efd3..12a6af31195 100644 --- a/build-tools/installers/create-installers.targets +++ b/build-tools/installers/create-installers.targets @@ -121,7 +121,6 @@ <_MSBuildFiles Include="$(MSBuildSrcDir)\cil-strip.pdb" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> <_MSBuildFiles Include="$(MSBuildSrcDir)\class-parse.exe" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> <_MSBuildFiles Include="$(MSBuildSrcDir)\class-parse.pdb" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> - <_MSBuildFiles Include="$(MSBuildSrcDir)\FSharp.Core.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\generator.exe" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> <_MSBuildFiles Include="$(MSBuildSrcDir)\generator.pdb" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " /> <_MSBuildFiles Include="$(MSBuildSrcDir)\HtmlAgilityPack.dll" /> @@ -401,6 +400,7 @@ <_MSBuildFiles Include="$(MSBuildSrcDir)\lib\x86\installer" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\lib\x86_64\installer" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\protobuf-net.dll" /> + <_MSBuildFiles Include="$(MSBuildSrcDir)\System.CodeDom.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\System.Collections.Immutable.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.AndroidTools.dll" /> <_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.AndroidTools.pdb" /> diff --git a/build-tools/scripts/RunTests.targets b/build-tools/scripts/RunTests.targets index 04693de6a7d..5352ae33221 100644 --- a/build-tools/scripts/RunTests.targets +++ b/build-tools/scripts/RunTests.targets @@ -15,7 +15,7 @@ <_XABuildProperties>$(_XABuildDiag)/p:Configuration=$(Configuration) - <_TestAssembly Include="$(_TopDir)\bin\Test$(Configuration)\Xamarin.Android.Build.Tests.dll" /> + <_TestAssembly Include="$(_TopDir)\bin\Test$(Configuration)\net472\Xamarin.Android.Build.Tests.dll" /> <_ApkTestProject Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" /> <_ApkTestProject Include="$(_TopDir)\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.csproj" /> <_ApkTestProject Include="$(_TopDir)\tests\CodeGen-MkBundle\Xamarin.Android.MakeBundle-Tests\Xamarin.Android.MakeBundle-Tests.csproj" /> diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs index 85b211cb857..b864d551fc0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs @@ -554,11 +554,11 @@ public void BindDefaultInterfaceMethods (string classParser) proj.SetProperty ("_EnableInterfaceMembers", "True"); proj.SetProperty ("LangVersion", "preview"); - using (var b = CreateDllBuilder (Path.Combine ("temp", TestName), false, false)) { + using (var b = CreateDllBuilder ()) { proj.NuGetRestore (b.ProjectDirectory); Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - string asmpath = Path.GetFullPath (Path.Combine (Path.GetDirectoryName (new Uri (GetType ().Assembly.CodeBase).LocalPath), b.ProjectDirectory, b.Output.OutputPath, (proj.AssemblyName ?? proj.ProjectName) + ".dll")); + string asmpath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll"); Assert.IsTrue (File.Exists (asmpath), "assembly does not exist"); var cs = b.Output.GetIntermediaryAsText (Path.Combine ("generated", "src", "Com.Xamarin.Test.IDefaultInterfaceMethods.cs")); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ManagedResourceParserTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ManagedResourceParserTests.cs index f6134fcd3a7..49a4725ad9f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ManagedResourceParserTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ManagedResourceParserTests.cs @@ -631,6 +631,7 @@ public void CompareAaptAndManagedParserOutputWithCustomIds () } [Test] + [NonParallelizable] // Test measures performance public void CheckPerformanceOfManagedParser () { var path = Path.Combine ("temp", TestName); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs index 815e074ca89..00750def7ee 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs @@ -256,7 +256,7 @@ public void ResolveSdkTiming () Assert.NotNull (resolveSdks.ReferenceAssemblyPaths, "ReferenceAssemblyPaths should not be null."); Assert.AreEqual (resolveSdks.ReferenceAssemblyPaths.Length, 1, "ReferenceAssemblyPaths should have 1 entry."); Assert.AreEqual (resolveSdks.ReferenceAssemblyPaths[0], Path.Combine (referencePath, "MonoAndroid"), $"ReferenceAssemblyPaths should be {Path.Combine (referencePath, "MonoAndroid")}."); - var expected = Path.Combine (Root); + var expected = Path.GetDirectoryName (GetType ().Assembly.Location); Assert.AreEqual (resolveSdks.MonoAndroidToolsPath, expected, $"MonoAndroidToolsPath should be {expected}"); expected += Path.DirectorySeparatorChar; if (resolveSdks.MonoAndroidBinPath != expected) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs index 79c6ef89f34..cbf97c7a663 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs @@ -40,7 +40,11 @@ public static string AndroidMSBuildDirectory { static SetUp () { - Builder.UseDotNet = string.Equals (TestContext.Parameters ["dotnet"], bool.TrueString, StringComparison.OrdinalIgnoreCase); +#if NETCOREAPP3_1 + Builder.UseDotNet = true; +#else + Builder.UseDotNet = false; +#endif using (var builder = new Builder ()) { CommercialBuildAvailable = File.Exists (Path.Combine (builder.AndroidMSBuildDirectory, "Xamarin.Android.Common.Debugging.targets")); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj index 6b29a08848f..b16145c23a0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj @@ -1,9 +1,8 @@ - net472 + net472;netcoreapp3.1 true - false ..\..\..\..\bin\Test$(Configuration) @@ -17,6 +16,12 @@ + + + + + + @@ -26,12 +31,15 @@ + ..\Expected\GenerateDesignerFileExpected.cs PreserveNewest + ..\Expected\GenerateDesignerFileWithElevenStyleableAttributesExpected.cs PreserveNewest + ..\Expected\GenerateDesignerFileWithLibraryReferenceExpected.cs PreserveNewest diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidCommonProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidCommonProject.cs index fe75b631b57..a470605bea3 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidCommonProject.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidCommonProject.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Microsoft.Build.Construction; -using System.Drawing; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Processing; namespace Xamarin.ProjectTools { @@ -19,22 +20,13 @@ public abstract class XamarinAndroidCommonProject : XamarinAndroidProject BuildItem.Source resourceDesigner; - static byte[] ScaleIcon (Image image, int width, int height) + static byte [] ScaleIcon (Image image, IImageFormat format, int width, int height) { float scale = Math.Min (width / image.Width, height / image.Height); - using (var bmp = new Bitmap ((int)width, (int)height)) { - using (var graphics = Graphics.FromImage (bmp)) { - var scaleWidth = (int)(image.Width * scale); - var scaleHeight = (int)(image.Height * scale); - using (var brush = new SolidBrush (Color.Transparent)) { - graphics.FillRectangle (brush, new RectangleF (0, 0, width, height)); - graphics.DrawImage (image, new Rectangle (((int)width - scaleWidth) / 2, ((int)height - scaleHeight) / 2, scaleWidth, scaleHeight)); - using (var ms = new MemoryStream ()) { - bmp.Save (ms, System.Drawing.Imaging.ImageFormat.Png); - return ms.ToArray (); - } - } - } + using (var ms = new MemoryStream ()) { + var clone = image.Clone (i => i.Resize (width, height)); + clone.Save (ms, format); + return ms.ToArray (); } } @@ -45,11 +37,11 @@ static XamarinAndroidCommonProject () stream.Read (icon_binary_mdpi, 0, (int) stream.Length); stream.Position = 0; - using (var icon = Bitmap.FromStream (stream)) { - icon_binary_hdpi = ScaleIcon (icon, 72, 72); - icon_binary_xhdpi = ScaleIcon (icon, 96, 96); - icon_binary_xxhdpi = ScaleIcon (icon, 144, 144); - icon_binary_xxxhdpi = ScaleIcon (icon, 192, 192); + using (var icon = Image.Load (stream, out var format)) { + icon_binary_hdpi = ScaleIcon (icon, format, 72, 72); + icon_binary_xhdpi = ScaleIcon (icon, format, 96, 96); + icon_binary_xxhdpi = ScaleIcon (icon, format, 144, 144); + icon_binary_xxxhdpi = ScaleIcon (icon, format, 192, 192); } } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj index 894ed2932ca..4695b00b0b7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj @@ -81,7 +81,7 @@ - + {E34BCFA0-CAA4-412C-AA1C-75DB8D67D157} diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 324927af39c..b4b04585266 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -35,7 +35,6 @@ - diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets index e583c32e903..cdd0f5d165b 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets @@ -343,7 +343,6 @@ - diff --git a/src/Xamarin.Android.Tools.Aidl/Xamarin.Android.Tools.Aidl.csproj b/src/Xamarin.Android.Tools.Aidl/Xamarin.Android.Tools.Aidl.csproj index d06baa32644..1cbdaa539b7 100644 --- a/src/Xamarin.Android.Tools.Aidl/Xamarin.Android.Tools.Aidl.csproj +++ b/src/Xamarin.Android.Tools.Aidl/Xamarin.Android.Tools.Aidl.csproj @@ -1,45 +1,15 @@ - - - - Debug - AnyCPU - {D27AD8F7-7710-40BE-B03B-55EFBEC13C44} - Library - Xamarin.AndroidTools.Aidl - Xamarin.Android.Tools.Aidl - True - + - - False - $(XAInstallPrefix)xbuild\Xamarin\Android - DEBUG; - prompt - 4 - False - - - True + + netstandard2.0 + false $(XAInstallPrefix)xbuild\Xamarin\Android - prompt - 4 - False - - ..\..\bin\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Cecil.dll - - - - - - - - - +