xamarin / Xamarin.Legacy.Sdk

Starting from a .NET 6 project, adds the ability to target legacy Xamarin target frameworks such as monoandroid11.0 or xamarin.ios10. *Not fully supported*

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should .NET Standard be implicitly referenced?

chucker opened this issue · comments

I have a C# wrapper around a native macOS library for Xamarin, and want it to work with .NET 6 as well. It also has a package reference to a .NET Standard library.

However, if I try to consume any enum from that package, I get:

 MyClass.cs(12,12): Error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

For example, with a csproj like:

<Project Sdk="Xamarin.Legacy.Sdk/0.1.2-alpha6">
  <PropertyGroup>
    <TargetFrameworks>xamarinmac2.0;net6.0-macos</TargetFrameworks>
    <Nullable>enable</Nullable>
    <NoNFloatUsing>true</NoNFloatUsing> <!-- https://github.com/xamarin/xamarin-macios/issues/14434 -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Text.Json" Version="6.0.3" />
  </ItemGroup>
</Project>

And a MyClass.cs like:

public class MyClass
{
	public MyClass()
	{
		var x = System.IO.FileAccess.Read; // an enum from .NET Standard
		var y = System.Text.Json.JsonTokenType.Comment; // an enum from a package
	}
}

This won't build. Oddly enough, the first line will build, and the second will not.

If I explicitly supply a hint path, it seems to work:

<ItemGroup Condition="'$(TargetFramework)' == 'xamarinmac2.0'">
  <Reference Include="netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
    <HintPath>/Library/Frameworks/Xamarin.Mac.framework/Versions/8.8.0.0/lib/mono/4.5/Facades/netstandard.dll</HintPath>
  </Reference>
</ItemGroup>

Is this intentional, or should the SDK pull in .NET Standard automatically?

The Mac support here was a community contribution, but it sounds like the Facades directory isn't setup appropriately for Xamarin.Mac.

I would probably compare a .binlog from a Xamarin.Mac class library and see if some MSBuild property has a different path we are missing. Probably something needed in this file:

https://github.com/xamarin/Xamarin.Legacy.Sdk/blob/main/src/Xamarin.Legacy.Sdk/Sdk/Xamarin.Legacy.macOS.targets