Tag Archives: Visual Studio

Getting Started in Xamarin Forms with Visual Studio 2017: Why Your First App Won’t Compile or Deploy

Visual Studio 2017 was just released with much fanfare, and if you work in the Windows world, your set of tools just got a major upgrade. One of the biggest toys in your new toolbox is the built-in support for Xamarin–a recent acquisition of Microsoft’s, and whose technology allows developers to write an app in C# that will deploy and run natively on iOS, Windows, and Android mobile devices. This is Really Big Stuff, and a technology which we’ll be spending a lot of time with in the coming years.

One of the more surprising aspects of the new Xamarin Forms support in Visual Studio 2017, however, is that the built-in templates for Forms-based projects don’t actually compile(!). These are the “Hello World” apps which are there to get novices (such as ourselves) started, so not being able to get them to… you know… work… is sort of unnerving.

After a couple of weeks dealing with Xamarin, here’s a few tips on how to get that first app running under Windows, using the Community edition of Visual Studio 2017. Hopefully Microsoft will fix much of this soon, but in the meantime, this article is for anyone who’s also getting their feet wet with Xamarin is might be getting flustered by the constant stream of errors standing between themselves and “Hello World”:

  1. You’ll likely need to install a new Windows SDK, or you’ll get errors when targeting different versions of Windows UWP. As soon as you choose to create a new “Cross Platform” project (iOS/Android/Windows), Visual Studio will go through the work of creating separate sub-projects for each one of these platforms. When it hits the UWP (Universal Windows Platform) one, you’ll be presented with a dialog asking you which version of Windows you want to target, and which level is the minimum you’ll support. Whatever you choose, there’s about an 80% change you don’t have the exact right version of the relevant Windows SDKs installed on your machine, and you’ll get a message with a “https://go.microsoft..” url as part of the error message. Copy that link into your browser’s address bar (the error message is not a hyperlink, unfortunately), and it’ll take you to the Windows  SDK download page. Install the relevant version, restart Visual Studio, and try again.

  2. Visual Studio Itself may need to be updated or you’ll get “(limited)” Mac Client connectivity and the iOS app won’t compile. After a day last week  spent wondering why my Mac Client was connecting with a “(limited)” next to the icon in the toolbar–and having the builds which worked the night before suddenly fail (and in desperation, spinning up a second Mac as a build computer only to have it also fail)–I discovered that Microsoft had just released a patch some 2 hours earlier to Visual Studio which solved the issue (itself likely caused by one of the Windows 10 updates that downloaded overnight). The solution: watch your “Notifications” in Visual Studio like a hawk, and download any updates you see there. You can also use Tools > Extensions and Updates to verify that you’ve got the very latest–and we do mean the very latest–updates.

  3. Your Android SDKs are out of date. If you want to work with the latest Android OSs (and you do), you’ll need to install more recent versions of the Android SDKs than are included with the Visual Studio 2017 install. The current versions of Xamarin (more on this later) also expect the Android SDKs to be updated. To do this, use Visual Studio’s Tools > Android > Android SDK Manager. Warning: the installs take a long time to complete, so throw on an episode or two of Breaking Bad before you kick them off.

  4. The default installed version of Xamarin is out of date, and will cause errors around InitializeComponent() in App.xaml.cs; when you try to compileThe solution: Before you do anything with a new project, right-click on the solution, go to Nuget Package Manager, click the Updates tab, and install all available updates. Then Do it Again as the Build component for Xamarin won’t update until the rest of it has updated. It’ll want to restart Visual Studio afterward, so do that too.

  5. Your Mac’s XCode and Xamarin also likely need updating. This is tedious. You’ll need the latest version of XCode… which in turn likely requires the latest version of the OS… along with the latest version of the Xamarin components (which you can get by downloading Xamarin Studio). It’s all pretty easily managed, but the installs take hours.

  6. The default project settings will nest the path too deeply and you’ll likely get deployment errors. By default, projects are created in the [My Documents]\Visual Studio 2017\Projects folder, creating a sub-folder for the project itself. Due to the depth of the folder nesting within the various sub-project folders, it’s far too easy to have some of the paths exceed Windows’ limit of 255 characters in the total path name. The solution: Don’t use the default location, and create the project’s directory as close to your drive’s root as possible.

  7. Your Android Devices need to be set up in developer mode to let you debug on the device. And trust me, after waiting several minutes for the emulators to boot up, you will want to debug on an actual device.The trick to turning on developer mode varies depending on the version of Android you’ve got. For mine (the “Marshmallow” version of Android), it involved tapping the Android OS version number a jillion times in a row under Settings. See http://www.androidcentral.com/android-50-lollipop-basics-how-turn-developer-settings or https://www.youtube.com/watch?v=TKIRXVhBvBY for more.

  8. Your iOS Devices need to be provisioned… and have their certificates set up… and a bunch of other stuff. The easiest way to handle all of this is through XCode. Start by paying the $99 to Apple to join their iOS developer program (you’ll need to bite the bullet and do it anyway if you distribute through their store), then connect your iOS device to your Mac, launch XCode, and follow the guide here: https://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/Oh, and that part about needing to create a dummy app to get the proper provisioning profile installed? That’s actually real.

Hope these tips give you a smoother ride getting started. I’ll undoubtedly be blogging more on Xamarin in the future…