I am going to show you the quickest way to do the upgrade, from an existing PCL, to a .NET Standard Class library, in Visual Studio 2017. Please note this will not work in VS 2015. Many of my previous posts don’t make it too clear on how to do this, due to the constantly changing nature of .NET Standard, especially between VS2015 and VS2017.
There is no way to do this via any upgrade tool, that I am aware of.
- Delete your packages.config and/or project.json file. We are going to have to add everything back manually. Keep a backup if you need to keep a reference.
- Right click, and press Unload Project
- Right click, and press edit projectname.csproj
- Delete everything in here.
- Replace with this xml
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard1.3</TargetFramework> <PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback> </PropertyGroup> </Project>
- Change the .NET Standard version to the one you want. However you will be able to change it from properties later.
- Remove this line, if you don’t want to support references to PCL’s
- Or, you can change this to support different profiles, if your project requires them.
- Reload your project.
- Manually add back references and Nuget Packages. It can be tedious on large projects, but it’s worth it.
- You may need to add back the reference to this project, from any other projects that were referencing it.
All Done 🙂
- VS 2017 .NET Standard libraries don’t support file nesting yet. As such ALL your *.xaml.cs files will be shown beneath your .xaml files.
- You will now be able to edit your .csproj, without unloading the project. Added plus!
- You can change the .NET Standard version, from properties now.
- I recommend .NET Standard 1.3, as it supports early versions of UWP, Android and iOS. I haven’t needed any API’s beyond this, at this point. But you can change as required.
- .NET Standard 2.0, is currently in preview in Android and iOS. UWP support for .NET Standard 2.0 is coming 2017, with the Fall Creators Update. However all Windows devices, must have the Fall Creators Update or higher to be compatible, with .NET Standard 2.0. This may be a good choice if you are starting a new project now, and won’t be releasing until the end of the year, by which time, they will all be out of preview.