Workaround if you have a lots of errors for your Xamarin projects in Visual Studio 2015

If you are running Xamarin projects in Visual Studio 2015 you maybe have a lot of error related to assemblies that not is referenced.

A lot of error in the error list.

A lot of error in the error list.

Even if there are errors the project will build successfully. Microsoft says this is a Xamarin bug and that the have reported it to Xamarin.

Until it’s fixed there are a workaround. On the top of the error list there are a filter where you can select source for the error list. The default source is Build + IntelliSense, if you select to just show  errors from build the errors will be gone from the list.

You can select source for the error list.

You can select source for the error list.

With "Build Only" the errors is gone.

With “Build Only” the errors is gone.

Preserve data when deploying Xamarin.Android app

By default all your data from your previous runs is deleted when you’re deploying an Xamarin.Android app. In many cases you don’t want the data to be deleted.

Visual Studio
To preserve data go to Tools -> Options -> Xamarin -> Android Settings and check “Preserve application data/cache on device between deploys”.Visual Studio

Xamarin Studio
To preserve data go to Tools -> Options -> Android and check “Preserve data/cache between application deploys”.
Xamarin Studio

Dependency Graph with NDepend

Right now I evuluating a new software called NDepend. NDepend is installad as a Visual Studio plugin. I havn’t use it much yet, but I have already found a feature that I like a lot. It is the dependency graph. The graph show how assemblies is related to other assemblies in your Visual Studio solution and to external assemblies. You can easily show information about an assembly buy hover over an assembly in the graph.

With Visual Studio Ultimate you can generate dependency graphs out of the box. But I think that the tool for dependency graphs in NDepend gives me a much better overview than the tool in Visual Studio Ultimate and  it much easier to use.

When I have evulated it more I will write a full review of the software.

 

 

Building a tabbed app using Xamarin.Forms

Xamarin.Forms is one of the biggest news with Xamarin 3. With Xamarin.Forms you can build UI for 3 platforms (Windows Phone, iOS and Android) with one shared codebase. What is unique for Xamarin.Forms is that the UI code you are writing with Xamarin.Forms will render native UI controls. That means that the UI will look like a Windows Phone app when running the code on a Windows Phone and it will look like a iPhone app when running the code on an iPhone and the same on Android.

Create a Xamarin.Forms project in Visual Studio
This post will show you the basics when building an app with Xamarin.Forms in Visual Studio 2013. You can also build apps using Xamarin.Forms with Xamarin Studio but for the Windows Phone project you need to use Visual Studio.

To create an app with Xamarin.Forms open the new project dialog. Xamarin.Forms project templates is located under “Mobile Apps”. There are three types of project you can create, a blank app with the code in a project of type portable class library (the project will be referenced in each client project), a blank app with shared code (you have to link the each file to each client project) and a class library of type portable class library.

In this tutorial I will use the first choice because I want Visual Studio to create the client projects (projects for Windows Phone, iOS and Android) and I think it’s easier to reference an assembly than linking files.

Create dialog

Now Visual Studio has created four projects, the client projects and a project for the shared UI code.

In the shared project I add a new item based on the template called “Forms Xaml Page”. Then a XAML-file and a code behind file is created.

Many of the tutorials I have read writes the most of the code in the code behind file, but I want to use XAML as much as possible. One disadvantage to use Visual Studio is that there is not intellisense for the XAML-code. If you miss it to much you can use Xamarin Studio instead.

Create an app with tabs

The app in this tutorial will be a app with two tabs/views and for that we will use a tabbed page. This post will just use standard styles. But you can both style the app for all platforms or you can do platform specific styling.

In the view we just created ad the code below. This will be a container for the views in the app.

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
					   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
					   x:Class="FormsDemo.FirstView"
            Title="News">
 
</TabbedPage>

You also need to go to the code behind file and make the class inherit from “TabbedPage”.

Next step is to create the content views, this app will have one for news and one for settings, so I add two new forms xaml pages to the shared project. Before I starting to create each view I will add them to the tabbed page. This is done from the code behind file of our “container”.

public partial class FirstView : TabbedPage
    {
        public FirstView()
        {
            InitializeComponent();
 
            Children.Add(new NewsView());
            Children.Add(new SettingsView());
 
        }
    }

The title for the tabs will be the title we set as Title property on ContentPage for each view.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
					   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
					   x:Class="FormsDemo.NewsView" Title="News">

Add a list to the app
My first tab will be a list with news. For that I using the ListView control that is included in Xamarin.Forms.

<ListView x:Name="News" ItemsSource="{Binding News}" RowHeight="80" BackgroundColor="Transparent">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <ViewCell.View>
            <StackLayout Orientation="Vertical" Spacing="0" Padding="10">
              <Label Font="Bold,20" Text="{Binding Header}" />
              <Label Font="16" Text="{Binding Text}" />
            </StackLayout>
          </ViewCell.View>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

And the code behind will look like this:

public partial class NewsView
    {
        public NewsView()
        {
            InitializeComponent();
 
            BindingContext = new NewsViewModel();
        }
    }
 
    public class NewsViewModel
    {
        public NewsViewModel()
        {
            News = new List<NewsItem>()
            {
                new NewsItem()
                {
                    Header = "Header 1",
                    Text = "Text 1"
                },
                new NewsItem()
                {
                    Header = "Header 2",
                    Text = "Text 2"
                }
            };
        }
 
        public List<NewsItem> News { get; set; }
    }
 
    public class NewsItem
    {
        public string Header { get; set; }
        public string Text { get; set; }
    }

iPhone

Windows Phone

Android

On the settings page I using the Switch control to turn news sources on or off.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
					   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
					   x:Class="FormsDemo.SettingsView">
  <StackLayout Orientation="Vertical" Padding="10">
	  <Label Font="Bold,20" Text="News sources" />
    <StackLayout Orientation="Horizontal">
      <Label Text="Xamarin" VerticalOptions="Center" />
      <Switch VerticalOptions="Center" />
    </StackLayout>
    <StackLayout Orientation="Horizontal">
      <Label Text="Microsoft" VerticalOptions="Center" />
      <Switch VerticalOptions="Center" />
    </StackLayout>
  </StackLayout>
</ContentPage>

Windows Phone

Android

iPhone


That was the basics to build an tabbed app with Xamarin.Forms. Of course you can do much more than this with Xamarin.Forms.

Error when syncing iOS SDK version with Xamarin build host

When I would deploy to the iOS simulator from Visual Studio I got a message that I hade to sync iOS SDK version with the build. But when I tried to sync I got an error that the sync process couldn’t connect to the server.

Then I tried to open Xamarin Studio to check if there was any updates for any of the Xamarin products. And there was an update for Xamarin 3.1, after installing that update I could sync the iOS SDK without errors.

It looks like you have to install updates (other than the Visual Studio plugin) to Xamarin via Xamarin Studio.

Problems with Xamarin iOS project and web project in same solution

In my Visual Studio solution I have both client projects and server side projects. The client projects are for Windows Phone, Xamarin iOS, Xamarin Android and WPF. The server side project is a Mobile Services .NET backend project.

My problems started yesterday when I would publish the latest update of my backend to Azure. I right clicked on the project and hit publish, then shown a dialog with the following text “object reference not set to an instance of an object”. To verify if it was a problem with my project or with Visual Studio I created a new solution with a new Mobile Services .NET project, and it worked. Then added the project from the old solution to the new solution and it worked. Then I started to think about the diffrences in my both solutions, so I added new client projects. After that I have added a new iOS project I got the same error when I trying to publish the Mobile Services project to Azure. When I removed the iOS projects from the old soultion and restarted Visual Studio it worked there to.

I also tried to create a new solution with a MVC project and a Xamarin iOS project to investigate if the problem was just for Mobile Services projects or for all web projects. It looks like the problem is for all web projects when you have a Xamarin iOS project in the same solution.

I using Visual Studio 2013 with update 2.

TypeScript will not compile on save in Visual Studio 2013

It seems that many having problem that TypeScript not will auto compile on save in Visual Studio 2013. TypeScript was earlier a part of the Web Essentials extension, but it is not included anymore. So the first step is to ensure that the TypeScript plugin is installed, if not it is available for download here, http://www.microsoft.com/en-us/download/details.aspx?id=34790.

If you still have the problem you need to activate auto compile on save for TypeScript.

To enable auto compile on save for TypeScript follow following steps:

  1. Go to Options under the Tools menu.
  2. Expand options for Text Editor
  3. Expand options for TypeScript
  4. Expand options for Project
  5. Check “Automatically compile TypeScript file which are not part of the project”

That helped me when my TypeScripts not compiled on save.

 

 

Workaround for invalid markup problems when developing for Windows Phone

Every time I open up a Windows Phone Project in Visual Studio 2013 I got a lots of  errors in the XAML markup. The designer shows “Invalid markup” and the error list is long. I found a workaround for this:

  1. Open Configuration Manager for your Visual Studio solution
  2. Change platform for the Windows Phone Project to x86
  3. Build the Project and the errors is gone
  4. Open Configuration Manager again and change back to “Any CPU”

After follow above steps it will work until you start Visual Studio again.

Windows Azure Mobile Services in Portable Class Library

In my current project, a multiplayer game for mobile devices I only using Windows Azure Mobile Services as backend. The game will be available for multiple platforms and I will use Xamarin for iOS and android.

When using Xamarin I can reuse a lot of code if I using PCL (Portal Class Library) that i shipped with Visual Studio. When creating a new PCL-project you can choose which taget platforms the project will build for, in my case Windows Phone, Windows Store, Xamarin iOS and Xamarin Android.

In order to reuse so much code as possible I want to have the communication with my backend in PCL. When using Windows Azure Mobile Services I can have all communication there except for the code for authentication. But then I put an interface i PCL and each platform will have a specific implementation of the interface.

But where to find the Mobile Services assemblies for PCL? I installed Mobile Services via NUGET to my Windows Phone project (Windows Phone is my first platform). But Mobile Services was not just installed to my Windows Phone project, I also got the assemblies for PCL (and other platforms) i my packages folder. It enabled me to add the assemblies manually to the PCL-project.

Solution: Web role deploy problem with Azure SDK 2.2

When I updated my Windows Azure SDK to 2.2 I got a problem when deploying the package of my MVC 4 web site from Visual Studio to a web role in Windows Azure. The message I got was that a exception has occored under recycling and that I should check for unhandled exceptions or configurations errors.

Finnaly I found the solution, setting Copy local to true on the reference to the assembly for WindowsAzure.ServiceRuntime made it work again.

Visual Studio performance and local workspace for TFS

I have had performance issues with Visual Studio for a long time. For example open projects, adding files and installing NuGet packages had taken very long time.

Last week I talked one of our TFS experts at Sogeti and he asked me how many files I had in my TFS workspace. I had more than 60 000 files in the workspace. I said that it could be the problem.

When using local workspace, Visual Studio scanning the file system for changes. If a workspace contains more than 50 000 files it could affect the performance.

I tried to split my workspaces into smaller parts, and he had right, Visual Studio is much faster now than before.

The conclusion of this is, try to keep your workspace as small as possible and if you have to have a workspace that contains more than 50 000 files, use server workspace instead.

Extensions for Visual Studio 2012

Visual Studio 2012 is a very good tool out of the box. But with a few extensions it will be even better. I using following extensions:

ReSharper 7
I can’t live without it! It makes my day much more effective.

VSCommands – Free
The feature I use most is the button that attach the debugger to IIS-processes.

Productivty Power Tools – Free
An add-on with small feature thats makes me more productive.

Web Essentials – Free
An extensions with a lot of features that helps me with my web projects.

TFS Power Tools – Free
Adds extra features fot Team Explorer. For exampled it adds more check in policies.