I have had a lot of developers telling me that they have wanted to switch to .NET Standard Libraries, but that they are worried about losing git history. I have also heard fears of compatibility with existing packages. Do not fear! It is so simple to switch over to .NET Standard and takes minutes!
Why .NET Standard 2.0
There is simply no reason not to be using .NET Standard 2.0 at this point (you can still target 1.4 if you need older UWP support, but just do 2.0!). It supports all of your favorite platforms including every single Xamarin platform, offers 20K+ more APIs than 1.X, and has a 70% API compatibility with NuGet packages today (it will also consume non-.NET Standard libraries in a compat mode). On top of that it is the future! It replaces PCL and Shared Projects (with multi-targeting, which I will save for another blog post) and will make your life as a cross-platform developer much more enjoyable.
Easy as 1,2,3,4 🐒
- 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)
That is it! You are done! Welcome to the wonderful world of .NET Standard 2.0! If you had any reference to other projects you will want to add those back in!
So Easy Let Me Show You
That is right, it is so easy that I shot an entire 6 minute video where I do this in real time!
To learn more about .NET Standard head over to the documentation and to follow along with my Git commits you can find the source code to the library I converted in the video over on my GitHub.
Additionally, Frank and I discussed .NET Standard on Merge Conflict: