Bug 60137 - Can't reference net461 project from Xamarin.iOS project
Summary: Can't reference net461 project from Xamarin.iOS project
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild ()
Version: XI 11.2 (d15-4)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-11 16:43 UTC by 999komi
Modified: 2017-10-12 18:35 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
VS version info (2.12 KB, text/plain)
2017-10-11 16:45 UTC, 999komi
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description 999komi 2017-10-11 16:43:34 UTC
If I create a fresh Xamarin.iOS solution, then add a sub-project targeting netstandard 2.0, I can add the sub-project as a reference to the parent project. Everything works just fine.

However, if I edit the .csproj file of the child project, so that the target framework line reads

       <TargetFramework>net461</TargetFramework>

then VS Mac gets all unhappy and complains about an "incompatible framework". Which is weird, since net461 is simply a collection of packages on top of netstandard 2.0.
Comment 1 999komi 2017-10-11 16:45:08 UTC
Created attachment 25275 [details]
VS version info
Comment 2 John Miller [MSFT] 2017-10-11 18:37:08 UTC
I was able to reproduce the error message following the steps above, which is:

/usr/local/share/dotnet/sdk/2.0.0-preview2-006497/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.Common.targets(5,5): Error: Project '/Users/johnmiller/Projects/TestCells/TestCellsLib/TestCellsLib.csproj' targets '.NETFramework,Version=v4.6.1'. It cannot be referenced by a project that targets 'Xamarin.iOS,Version=v1.0'. (TestCells)
Comment 4 Matt Ward 2017-10-11 19:58:28 UTC
Not sure what the plans are for Xamarin.iOS. Whilst .NET Standard 2.0 projects can use .NET Framework assemblies whether those .NET Framework assemblies will work still needs to be tested by you. If you install a NuGet package, that only contains .NET Framework assemblies, into a .NET Standard 2.0 SDK style project you will see a warning saying that the package may not be compatible. You cannot install such a NuGet package into a Xamarin.iOS project since NuGet will prevent that.

The build error that John has commented is from .NET Core SDK which has no knowledge about Xamarin.iOS. .NET Core SDK only knows about .NETCore, .NETStandard and .NETFramework.

The following blog post has more information about this and says that 70% of the NuGet packages on nuget.org are compatible with .NET Standard 2.0 - which still leaves 30% which are not - and does not tell you which ones are not compatible.

https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-standard-2-0/

".NET Framework compatibility mode: The vast majority of NuGet packages are currently still targeting .NET Framework. Many projects are currently blocked from moving to .NET Standard because not all their dependencies are targeting .NET Standard yet. That’s why we added a compatibility mode that allows .NET Standard projects to reference .NET Framework libraries. While this may not work in all cases (for instance, if the .NET Framework binaries use WPF) we found that 70% of all NuGet packages on nuget.org are API compatible with .NET Standard 2.0. So in practice it unblocks many projects."


Currently a Xamarin.iOS project can reference another Xamarin.iOS project, a PCL project or a .NET Standard project. It cannot reference a .NET Framework project or a .NET Framework assembly. Installing a NuGet package that only contains .NET Framework assemblies will also be blocked by NuGet since it considers it to not be compatible. Not sure if this will change - possibly NuGet package authors will provide .NET Standard assemblies and then this problem will be resolved that way.
Comment 5 Jeffrey Stedfast 2017-10-12 18:35:02 UTC
We don't support referencing .NET 4.x (or older) assemblies. .NET 4.x assemblies can use APIs not included in the Xamarin.iOS subset.