Debugging Xamarin.Forms from GitHub

download.png

This is for version 3.4.0 and under, see below for 3.5.0 changes

Sometimes strange things happen in your app, it could be that a problem deep in Xamarin.Forms is the cause. Here’s a very condensed, simple way to have your App point to the Xamarin.Forms code so that errors can be caught and causes more easily determined.

Note: Breaking changes in 3.5.0, see below

This is heavily based on the guide at Xamarin, but simplified and condensed into a path I found that works.

For Windows – Visual Studio 2017/2019

Get the Code:

Install the GitHub Desktop application.

GOTCHA: If you’ve tried before delete any repo and start fresh.

Run it and choose the opportunity to Clone a repository from a Url. Enter the URL https://github.com/xamarin/Xamarin.Forms . I put my repos into E:\GitHub

2019-02-06 14_04_12-GitHub Desktop.png

Build the Code in Visual Studio

Turn off Resharper if you have it, it’ll slow you down really badly. You can re-enable it later.

Go to your repo, in my case E:\GitHub and open Xamarin.Forms.sln

Switch to the version branch you want to debug, like 3.4.0

When it loads in Visual Studio, Switch to Any CPU, then Build the Solution. This can take 5 minutes!!  You will see errors probably. You should be able to ignore them.

GOTCHA!! It must be Any CPU

2019-02-06 14_05_50-Maximizer - Microsoft Visual Studio  (Administrator).png

Close Visual Studio

Build the NuGet

Add a System Environment variable to where you have NuGet.exe. I put mine in e:\GitHub\

GOTCHA!! Add a \ to the end of the folder

2019-02-06 14_09_51-New System Variable.png

Open a Command Prompt and go to the main folder in the repo. In my case E:\GitHub\Xamarin.Forms

Run the batch file .create-nuget.bat all

GOTCHA – Did you forget the all parameter?

2019-02-06 14_12_20-Command Prompt.png

When done, there will be a new file named something like Xamarin.Forms.9.9.0.nupkg in the .nuspec folder

2019-02-06 14_14_10-.nuspec.png

Copy this file to a new Folder which will serve as your NuGet folder. I use E:\NuGetServer

2019-02-06 14_15_12-NuGetServer.png

Open your app, then add a new Nuget server pointing to that folder.

2019-02-06 14_15_53-Options.png

Now update your Xamarin Forms Package to point to your NuGet folder. Notice the version is 9.9.0.

2019-02-06 14_17_03-Maximizer - Microsoft Visual Studio  (Administrator).png

GOTCHA!! Manually delete all bin and obj folders and restart Visual Studio. I’ve had strange things happen when I switch Xamarin Forms versions if I don’t.

Run your app!

Now when there is an error, Visual Studio will step into the Xamarin.Forms code

Changes for version 3.5.0 onwards

Switching to Cake and powershell

Go to the Xamarin.Forms folder in Powershell, then allow for all scripts to be run with this:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

Then you can run the Build PowerShell:
./Build.ps1 -Target NugetPack 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s