Adding the Microsoft.Windows.Compatibility NuGet package fixed this error in my case without adding the magic lines to the csproj file.