Setting up Xamarin Forms Development for you and your team

In this series we will be learning the steps to achieve a development setup with Xamarin that will enable you to develop quickly and securely, and also allow you to have some fun while doing it. Let’s dive right in.

Part 1. Initial project

There are several ways to get started with Xamarin Forms. The easiest is probably to install Visual Studio (Visual Studio Community edition is free). Make sure to pick the ‘Mobile Development’ workload when installing.

Once Visual Studio is installed, open it, and choose ‘Create a new project’. Select ‘Mobile App (Xamarin Forms)’, choose a name and where you want to save it, and then choose a template. Don’t worry, you will be able to change this later. If you’re not sure which one to pick, go with ‘Flyout’. It is a common enough UI pattern for mobile apps and will likely do just fine for your purposes.

The project that was just generated contains some examples for you to explore. I won’t go into the details of these, but if you’re not familliar with Xamarin Forms see this as an opportunity to explore some basic features of the platform. Once you’re done exploring, feel free to remove any of the generated code that you do not need. Once you’ve deleted any code that you don’t need, run the project to make sure everything still works.

I will try to refrain from telling you exactly how you could/should work with git in your work, but now would be a good time to make your first commit in the repository.

Even though we now have a working, basic, solution, we are not quite there yet. To properly prove that everything we make works as intended (and keeps working as intended) we are going to add tests.

Go ahead and add a unit test project to your solution. If you don’t know what unit tests are, or how to add a unit test project to a solution, I suggest you look up the basics. We won’t go into further details regarding unit tests in this series. Optionally, add an integration test project, which will simulate any communication with external dependencies to ensure everything stays compatible.

“But wait”, I hear you saying. “A mobile app is a visual thing. How are we supposed to test that things like clicking a button will actually open a new screen”. That’s where Xamarin UITest comes in, we will dive into that in a future post. Until then, we will be adding an empty UI Test project and setup the prerequisites so that when the time comes, it will be easy to start writing UI tests. Feel free to skip this part if you feel UI Tests are redundant.

Add a new project to your solution and pick ‘Xamarin.UITest cross platform test project’. Follow the official docs to properly set everything up.

The last thing I would recommend you add is a dependency injection library or framework like TinyIoC or Autofac. In addition, consider using a framework like MvvmCross or Prism to get a lot of useful utilities out of the box, including dependency injection.

Check out an example project here

Now that we have a solution that (hopefully) builds and runs, and includes all the means to write robust code, it’s time to setup our pipelines for Continuous Integration and/or Continuous Deployment/Delivery. We will tackle this in part 2.