пʼятниця, 23 червня 2017 р.

Compilation: every .cs file in .csproj


You should add a .cs file to the Sample.csproje, to the appropriate <ItemGroup> manually:

<Compile Include="MyButton.cs" />

otherwise you may get this:

I/MonoDroid( 2017): UNHANDLED EXCEPTION:
I/MonoDroid( 2017): Xamarin.Forms.Xaml.XamlParseException: Position 8:3. Type local:MyButton not found in xmlns clr-namespace:Sample

P.S. seems that MonoDevelop may add it automatically.

Compilation prerequisites

On Linux you can't create the Xamarin.Forms project from zero.

And for the compilation it is necessary to take the good template (!!!),
then msbuild will compile it correctly in many cases,
otherwise you may have a very strange errors in runtime,
or you will be able to build it only with xbuld.

Today you may try to use the xamarin-forms-samples for your experiments.

Sample.sln

Please comment out #
lines for iOS (and other, UWP, if any) project(s) - there are 3 lines for each project to comment out.

And every Sample.Droid.csproj will need the next:

<PropertyGroup Condition=" '$(OS)' == 'Unix' ">
  <AndroidSdkDirectory>/home/workerlamp/android-toolchain/sdk</AndroidSdkDirectory>
</PropertyGroup>

(please refer to this link to use more properties)

Also I set for all three PropertyGroup(s) the next line

<AndroidSupportedAbis>armeabi-v7a,x86</AndroidSupportedAbis>

x86 allows me to run it on emulator,

but if I will set pure "armeabi" as in some of examples it will not work on emulator at all,
but "armeabi-v7a" and "x86" works ok for me.
Usually I use only x86: <AndroidSupportedAbis>x86</AndroidSupportedAbis>

I don't know is it possible to make release builds on Linux to work on different devices, but for the development it is enough.

Making the xaml page


It is not enough to create 2 files:

SomePage2.xaml

<?xml version="1.0" encoding="utf-8"?>
  <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:Sample" x:Class="Sample.SomePage2">
  <Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

SomePage2.xaml.cs

using Xamarin.Forms;
  namespace Sample
  {
    public partial class SomePage2 : ContentPage
    {
      public SomePage2()
     {
       InitializeComponent();
     }
   }
 }

Additionally you will need to edit the Sample.csproj file manually, for example:

<ItemGroup>
  <EmbeddedResource Include="App.xaml" />
  <EmbeddedResource Include="SamplePage.xaml" />
  <EmbeddedResource Include="SomePage2.xaml" />
</ItemGroup>

<ItemGroup>
  <Compile Include="App.xaml.cs">
    <DependentUpon>App.xaml</DependentUpon>
  </Compile>
  <Compile Include="SamplePage.xaml.cs">
    <DependentUpon>SamplePage.xaml</DependentUpon>
  </Compile>
  <Compile Include="SomePage2.xaml.cs">
    <DependentUpon>SomePage2.xaml</DependentUpon>
  </Compile>
...
</ItemGroup>

Visual Studio Code

Visual Studio Code has a limited functionality today, but it is maybe the best tool I see today:

File system links:

~/.vscode/extensions/ms-vscode.csharp-1.10.0/bin

xbuild -> /usr/lib/mono/xbuild
xbuild-frameworks -> /usr/lib/mono/xbuild-frameworks/

~/.vscode/extensions/ms-vscode.csharp-1.10.0/bin/omnisharp/msbuild

Novell -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell
Xamarin -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Xamarin

where /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/ is my build path for xamarin-android.

File system links


Usually many of C# IDE on Linux are using the msbuild,
but if you will try to use the msbuild from the command line (you must try it to tune an IDE) you will see the different errors, because it can't find either some targets or it can't find the "The reference assemblies for framework MonoAndroid,Version=v1.0" (thanks to this developer who helped me to fix the MonoAndroid issue).

So we may use the symbolic links:

Path: /usr/lib/mono/xbuild

Novell -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell
Xamarin -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Xamarin

Path: /usr/lib/mono/xbuild-frameworks

MonoAndroid -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid


Path: /usr/lib/mono/msbuild/15.0/bin

Novell -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell
Xamarin -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Xamarin

where /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/ is my build path for xamarin-android.
I use the "ln -s directory" to make a link,
for example:
cd /usr/lib/mono/xbuild
ln -s /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell