Exercise - Create your Xamarin.Forms app with Xamarin.Essentials
The application you're building is a cross-platform mobile app that talks to the Azure Functions to share your location. In this unit, you'll create a blank mobile app using Visual Studio and install a NuGet package that has an API for getting the user's location.
To complete the steps in this unit, you need Xamarin.Forms cross-platform UI toolkit and the Universal Windows Platform Development workload installed in your Visual Studio. If you don't have this already, visit installing Xamarin.
Create the Xamarin.Forms project
From Visual Studio, select File > New > Project....
Use the search bar to find Mobile App (Xamarin.Forms), choose the item, and select Next.
Name the solution "ImHere".
Choose an appropriate location for the solution.
Select Create.
From the New Mobile App dialog, select the Blank App template.
For this module you'll build a UWP app, so uncheck iOS and Android and leave Windows UWP checked.
Select Create.
Visual Studio will create two projects for you
- UWP app named
ImHere.UWP
- .NET Standard library named
ImHere
Xamarin.Forms apps are made up of two parts - one or more platform-specific app projects, and - one (or more) .NET Standard libraries.
The platform-specific app projects contain the platform-specific code needed to run an app on the relevant platform. These projects then launch a Xamarin.Forms app that is defined in a cross-platform .NET Standard library. You build your app in cross-platform code and, at runtime, any user interfaces you create are translated into the relevant platform-specific UI components.
Adding Xamarin.Essentials
The UWP, Android, and iOS platforms provide numerous similar capabilities that take advantage of the operating system and hardware. Despite these similarities, the APIs are very different. Using these APIs from cross-platform code requires writing platform-specific code in your app projects that you expose to your .NET Standard libraries. Xamarin.Essentials is a NuGet package that provides a cross-platform abstraction over a number of these APIs so that you don't need to write platform-specific code. This includes the geolocation APIs that you'll use in your app to get the user's location.
Right-click on the
ImHere
solution (the top level solution, not theImHere
.NET Standard project) in the Visual Studio Solution Explorer and select Manage NuGet Packages for Solution....Select the Browse tab and search for "Xamarin.Essentials".
Tip
If you do not see the Xamarin.Essentials NuGet package, double check that include prelease is checked.
Select the Xamarin.Essentials NuGet package.
Check all your projects in the project list on the right-hand side.
Select the Install button to install the NuGet package. You'll need to accept the license to continue.
Building and running the app
Right-click on the
ImHere.UWP
project in Solution Explorer and select Set as StartUp project.Set the build configuration to Debug, the platform to x86, and the device to run on to Local Machine.
Start debugging the app.
Summary
In this unit, you created a new Xamarin.Forms cross-platform mobile app and added the Xamarin.Essentials NuGet package. Next, you'll learn how to build up the mobile app UI and logic.