Every time you create a new Xamarin.Forms project in Visual Studio for Mac you have to manually convert it to .NET Standard. The conversion is very straightforward and can be done with just a few steps:
How to Convert a Portable Class Library to .NET Standard and Keep Git History
- Unload your PCL project (right click -> unload), and start editing it (right -> click edit)
- Delete Everything in the csproj and insert this:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <!--<PackageReference Include="" Version=""/>--> </ItemGroup> </Project>
- Add back NuGets (simply open packages.config, and add the package references above, or via the NuGet package manager.
- Delete AssemblyInfo.cs (this is now in the csproj) and packages.config (also in csproj via PackageReference)
Hopefully one day VS team will take care of it, till then, I decided to automate this process and created an add-in/extension for VS for Mac – Mutatio.
Mutatio – in Latin means change, transformation or exchange.
Mutatio can convert newly created or existing projects. Please keep in mind that there might be
NuGet packages that does not support .NET Standard 2.0, in this case you may see related exceptions.
In case you change your mind and you want to rollback,
Mutatio is making a backup of all the files it modifying and deleting under the project’s root directory within
mutatio_backup folder. So all you have to do is to copy the files back to your project and reload the solution.
One of the biggest challenges I met while development was related to reloading the project after conversion. Within VS for Mac after manually modifying the
*.csproj under the right click menu of the project there will appear a
Reload option, however I didn’t find a way to call this method programatically. Currently, the whole solution will be reloaded as a workaround. If you know how to solve the problem programatically I would really appreciate if you will share your knowledge by contributing or leaving a comment.
More details can be found on GitHub.