Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

Should .NET Standard be implicitly referenced? #37

@chucker

Description

@chucker

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions