I'm trying to create some unit tests for my cross-platform (Android/iOS/UWP) Xamarin C# project. My target for the UWP version of the app is a Windows Surface tablet. Here's what I did.
- In Visual Studio 2017 Community, File:New:Project, pick Cross Platform App
- Specify Blank App, Portable Class Library (the app I'm building is PCL so I'm assuming the unit tests should also be PCL)
- In response to the question about target & minimum platform versions for my Universal Windows application, I selected "Windows 10 Creators Update" for both minimum and target (my app requires this, so again trying to make the unit tests as similar to the actual app as possible)
- Manage NuGet packages, notice that Xamarin.Forms has an update (from 2.3.4.224 to 2.3.4.231). Do the update. Successful.
In the NuGet Package Manager, select xunit v2.2.0 and click install. Get this error:
Could not install package 'xunit.assert 2.2.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', 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.
Check the properties for my project, see that it has a lot of targets: .NET Framework 4.5, ASP.NET Core 1.0, Windows 8, Windows Phone 3.1, Windows Phone Silverlight 8, Xamarin.Android, Xamarin.iOS, Xamarin.iOS (Classic), and Xamarin.Mac. Hit the "Change" button.
Uncheck Xamarin.Mac, .NET Framework 4.5, and ASP.NET Core 1.0. Add check for Windows Universal 10.0. Click OK. Get error:
The project's targets cannot be changed. The selected targets require the project to opt-into NuGet 3.0 support, however Visual Studio cannot automatically do this for you. Please uninstall all NuGet packages and try again.
OK fine, back to NuGet Package Manager, uninstall Xamarin.Forms.
- Back to Properties, change the targets, click OK. Screen flashes a little bit and then I'm back at the Properties page (as expected), and the targets don't match what I requested. My new targets are .NET Framework 4.5.1, Windows 8.1, Xamarin.Android, Xamarin.iOS, Xamarin.iOS (Classic), and Xamarin.Mac.
- Back to NuGet Package Manager, re-install Xamarin.Forms. Ask to install xunit. Accept the licenses.
Get new error:
Could not install package 'System.Runtime.InteropServices.RuntimeInformation 4.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.6,Profile=Profile44', 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.
Go back to the main project's properties, it still says it's targeting .NET Framework 4.5.1, not 4.6.
So how do I get xunit to work with Xamarin in Visual Studio 2017?