I started out using a .NET Standard Library project - to which I intend to build a NuGet out of in the future. But I found myself needing to write platform specific code.
I have seen approaches of editing the csproj file here and here - to add more targets. And I have also seen the Multiplatform Library
library project type.
But using Multiplatform
I found a NuGet package breaking:
Could not install package 'NObservable 0.1.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author
which assume is because the target with that library type becomes NETPortable
instead of netstandard2.0
.
Can I add more targets to the .NET Standard Library project by editing csproj
to be able to write platform specific code - or will I have to use the Multiplatform
library type - and delete the NuGets that are breaking? Is it possible to use .NET Standard and write platform specific code?
It is not supported yet in Visual Studio for Mac: https://stackoverflow.com/questions/57173464/how-to-multitarget-in-xamarin-forms-with-visual-studio-for-mac/57191608#57191608
Answers
We don't recommend you to place platform specific code on Forms project which is using .Net Standard library. And you can't do that unless installed Xamarin.iOS or Xamarin.Android on Forms. But I don't think this will be a good experience.
If you want to create a nuget packages for Xamarin follow these documentations:
https://docs.microsoft.com/en-us/nuget/guides/create-packages-for-xamarin
https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/nuget-manual
The guide in the first link involves installing
plugin for xamarin templates extension
- which I don't think can be installed in Visual Studio For Mac that I am using. In the second link I am referred to Multiplatform Library Project - using visual studio for mac.It is not supported yet in Visual Studio for Mac: https://stackoverflow.com/questions/57173464/how-to-multitarget-in-xamarin-forms-with-visual-studio-for-mac/57191608#57191608