T.Moore
T.Moore

Reputation: 11

What project type can reference .NET assemblies and can be referenced by an iOS Xamarin app

I'm looking for some help to setup my Visual Studio for Mac project properly. I'm new to Visual Studio Mac and would appreciate a shove down the right road.

I have a large class library, originally developed in visual studio 2017 on Windows.I'd like to use much of that code to develop an iOS application. This class library requires references to:

I have tried porting that code to a Portable Class Library in Visual Studio for Mac. However PCLs don't allow you to reference the above assemblies (unless I'm missing something).

So I then ported it to .NET Library project (Other -> .NET -> Library) project. However, my iOS app won't allow references to that project type because VS for Mac says it has an "Incompatible Target Framework: .NETFramework, Version-v4.6.1).

What project type should I be using for this class library so that it can reference the needed .NET assemblies and it can be referenced from my iOS application?

Upvotes: 1

Views: 410

Answers (1)

Matt Ward
Matt Ward

Reputation: 47967

Possible options:

  1. Use a different Portable Class Library (PCL) profile.
  2. Use a .NET Standard project.
  3. Use a shared project.

For everything apart from System.Web, there are PCL profiles that have the assemblies you are looking for. You can see which assemblies are available on the Mac by looking in the PCL directory:

/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETPortable

If you open a terminal window there you can run a search, find . -name "System.ServiceModel.Web.dll", or browse the folders using Finder to find a PCL profile that has the assemblies you need.

Another possibility would be to use a .NET Standard 2.0 project which has a lot of assemblies that can be used and supports being referenced by a Xamarin.iOS project. You may need to install some other System.* NuGet packages to provide the required assemblies.

The namespaces available in .NET Standard 2.0 are documented:

https://learn.microsoft.com/en-us/dotnet/api/?view=netstandard-2.0

Another option is using a shared project. This does not have assembly references itself but is basically shared code that is compiled into all projects that reference it. Here you can use #ifdefs for any code that is iOS or Android specific.

Upvotes: 1

Related Questions