XAM160 SQLite and Mobile Data

Exercise 2: Add SQLite.Net

In this exercise, you will add the SQLite.NET component to each project in your solution using NuGet.

We are going to continue with the People project you built in the prior exercise.

This exercise is a continuation of the previous exercise. You can use your existing solution or begin from the prior Exercise 1 > Completed solution in your copy of the cloned or downloaded course materials.

To complete the exercise, you will need Visual Studio for Windows or macOS with the Xamarin development tools installed. You will also need either an emulator/simulator or a device to run the exercise on. Please see the setup page if you need help installing the Xamarin development environment.

Add SQLite.NET

As a first step, we'll add the SQLite.NET NuGet package to each project in the solution. It includes platform-specific code in some cases so it must be included in every platform-specific project.

  1. Right-click on the 'People' solution root node in the solution explorer and select Manage NuGet Packages for Solution....
  2. Select the Browse tab and enter sqlite-net-pcl in the Search field.
  3. Select sqlite-net-pcl by Frank A. Krueger in the list of search results and press the Install button. Make sure you get the right package as there are several to choose from.
  4. Make sure all your projects are selected on the right and click the Install button to add the NuGet package to each one.

To add this NuGet package via the Package Manager Console, found in the menu under Tools > NuGet Package Manager > Package Manager Console, run the following command:

Install-Package sqlite-net-pcl

Adding the sqlite-net-pcl NuGet package to all solution projects in Visual Studio.
Install the sqlite-net-pcl package for all projects
  1. Expand all the projects in the Solution Explorer. Each project has a Packages folder where we will add the NuGet package.
  2. Right-click on the Packages folder in the People Portable Class Library project and select Add Packages... from the popup menu.
  3. In the Search field, enter sqlite-net pcl.
  4. Select sqlite-net-pcl by Frank A. Krueger in the list of search results, make sure it's checked and press the Add Package button in the lower right. Make sure you get the right package as there are several to choose from.
  5. Repeat the steps above for all other projects in the solution. VS for Mac makes this a little easier by always placing previously added packages first in the dialog when you open it again.
Adding the sqlite-net-pcl NuGet package to a project in Visual Studio.
Install the sqlite-net-pcl package for each project

Exercise summary

In this exercise, we added SQLite.NET to each project through NuGet. We're now ready to work with a SQLite database.

You can view the completed solution in the Exercise 2 > Completed folder of your copy of the cloned or downloaded course materials.

Go Back