Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests, build] multi-target Xamarin.Android.Build.Tests #4980

Conversation

jonathanpeppers
Copy link
Member

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:

<TargetFrameworks>net472;net5.0</TargetFrameworks>

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:

<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>

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.

@jonathanpeppers jonathanpeppers force-pushed the dotnet-multi-target-msbuild-tests branch 16 times, most recently from 05f5ff1 to 2365849 Compare August 12, 2020 20:41
@jonathanpeppers jonathanpeppers force-pushed the dotnet-multi-target-msbuild-tests branch 2 times, most recently from a3979d5 to f1481ab Compare August 14, 2020 16:13
@jonathanpeppers
Copy link
Member Author

Here is a build with a full run of the One .NET tests: https://build.azdo.io/3979182

@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 15, 2020 04:34
There are various tests in `Xamarin.Android.Build.Tests` that execute
MSBuild tasks directly. This means the changes in dotnet#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:

    <TargetFrameworks>net472;net5.0</TargetFrameworks>

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:

    <TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>

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/
@jonathanpeppers jonathanpeppers force-pushed the dotnet-multi-target-msbuild-tests branch from f1481ab to 5e4eb0e Compare August 17, 2020 19:05
@@ -270,9 +270,6 @@
BeforeTargets="CoreCompile"
Inputs="@(_SharedRuntimeAssemblies)"
Outputs="$(_GeneratedProfileClass)">
<ItemGroup>
<_SharedRuntimeAssemblies Remove="$(_SharedRuntimeBuildPath)v1.0\FSharp.Core.dll" />
</ItemGroup>
Copy link
Member Author

@jonathanpeppers jonathanpeppers Aug 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked src\Xamarin.Android.Build.Tasks\obj\Debug\Profile.g.cs and FSharp.Core.dll isn't being written to it at all, after this was removed:

using System.Collections.Generic;

namespace Xamarin.Android.Tasks {
	public partial class Profile {
		// KEEP THIS SORTED ALPHABETICALLY, CASE-INSENSITIVE
		public static readonly string [] SharedRuntimeAssemblies = new []{
			"I18N.CJK.dll",
			"I18N.dll",
			"I18N.MidEast.dll",
			"I18N.Other.dll",
			"I18N.Rare.dll",
			"I18N.West.dll",
			"Java.Interop.dll",
			"Microsoft.CSharp.dll",
			"Mono.Android.dll",
			"Mono.Android.Export.dll",
			"Mono.Btls.Interface.dll",
			"Mono.CompilerServices.SymbolWriter.dll",
			"Mono.CSharp.dll",
			"Mono.Data.Sqlite.dll",
			"Mono.Data.Tds.dll",
			"Mono.Posix.dll",
			"Mono.Security.dll",
			"mscorlib.dll",
			"OpenTK.dll",
			"OpenTK-1.0.dll",
			"System.ComponentModel.Composition.dll",
			"System.ComponentModel.DataAnnotations.dll",
			"System.Core.dll",
			"System.Data.DataSetExtensions.dll",
			"System.Data.dll",
			"System.Data.Services.Client.dll",
			"System.dll",
			"System.EnterpriseServices.dll",
			"System.IdentityModel.dll",
			"System.IO.Compression.dll",
			"System.IO.Compression.FileSystem.dll",
			"System.Json.dll",
			"System.Net.dll",
			"System.Net.Http.dll",
			"System.Net.Http.WinHttpHandler.dll",
			"System.Numerics.dll",
			"System.Numerics.Vectors.dll",
			"System.Reflection.Context.dll",
			"System.Runtime.CompilerServices.Unsafe.dll",
			"System.Runtime.Serialization.dll",
			"System.Security.dll",
			"System.ServiceModel.dll",
			"System.ServiceModel.Internals.dll",
			"System.ServiceModel.Web.dll",
			"System.Transactions.dll",
			"System.Web.Services.dll",
			"System.Windows.dll",
			"System.Xml.dll",
			"System.Xml.Linq.dll",
			"System.Xml.Serialization.dll",
		};
	}
}

@jonathanpeppers jonathanpeppers merged commit ff9a005 into dotnet:master Aug 18, 2020
@jonathanpeppers jonathanpeppers deleted the dotnet-multi-target-msbuild-tests branch August 18, 2020 13:03
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants