MSBuild command line to compile Xamarin projects

Xamarin Platform:

  • C# language - Build applications using the C# language
  • Mono .NET framework - Microsoft's cross-platform framework
  • Compiler - Compiler that generates different products according to different platforms
  • IDE tools - Integrated development environment, including creation, construction, deployment, compilation, etc.


Compilation
我们先看一下官网的描述:

The C# source makes its way into a native app in very different ways on each platform:

iOS – C# is ahead-of-time (AOT) compiled to ARM assembly language. The .NET framework is included, with unused classes being stripped out during linking to reduce the application size. Apple does not allow runtime code generation on iOS, so some language features are not available (see Xamarin.iOS Limitations ).
Android – C# is compiled to IL and packaged with MonoVM + JIT’ing. Unused classes in the framework are stripped out during linking. The application runs side-by-side with Java/ART (Android runtime) and interacts with the native types via JNI (see Xamarin.Android Limitations ).
Windows Phone – C# is compiled to IL and executed by the built-in runtime, and does not require Xamarin tools. Designing Windows Phone applications following Xamarin's guidance makes it simpler to re-use the code on iOS and Android.

Learn the Android compilation process first , you can compare the Android application developed in the java language:

Android application compilation and execution process developed by java:
Java --- (JavaC) ----> .class ---> JVM load class ---> main method execution

Xamarin platform C# application compilation execution process:
C# (.cs file) --- (C# complier) ---> IL ---> MonoVM + JIT execute

C# complier:
gmcs: compiler to target the 2.0 mscorlib.smcs
: compiler to target the 2.1 mscorlib, to build Moonlight applications.
dmcs: compiler to target the 4.0 mscorlib.

Xamarin compiles and packages executable programs:

first take a look at the official website introduction:
The Xamarin.Android build process is based on MSBuild, which is also the project file format used by Xamarin Studio and Visual Studio. * Ordinarily users will not need to edit the MSBuild files by hand* - the IDE creates fully functional projects and updates them with any changes made, and automatically invoke build targets as needed.

Advanced users may wish to do things not supported by the IDE's GUI, so the build process is customisable by editing the project file directly. This page documents only the Xamarin.Android-specific features and customizations - many more things are possible with the normal MSBuild items, properties and targets.

Windows 使用MSBuild, OS X 使用xbuild

Windows编译打包:
1. 确保环境已安装好 Visual Studio, Mono for Android SDK等
2. Find the file XXX.csproj with the suffix csproj in the project directory created by Xamarin
3. Find the MSBuild.exe provided by Mono
Note: The following is the method I found: Open XXX.csproj and look for <Import Project="$(MSBuildExtensionsPath )\Xamarin\Android\Xamarin.Android.CSharp.targets" />

Search for Xamarin.Android.CSharp.targets in the folder and find C:\Program Files (x86)\MSBuild\14.0 in the same directory of MSBuild \Bin\MSBuild.exe
4. Open the command line and execute the command to compile and package:
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /t:SignAndroidPackage Path\To\Your\XXX.csproj

After the package is completed, you can see that the signed and unsigned apk can be found in the \bin\Debug folder of the project.
If you need to package the Release version, you can add the field /p:Configuration=Release

Reference link:
Xamarin guide
https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_1_-_understanding_the_xamarin_mobile_platform/
https://developer.xamarin.com/guides/android/under_the_hood/build_process/

MSBuild commands:
https://msdn .microsoft.com/en-us/library/ms164311.aspx

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326861078&siteId=291194637