MSBuild命令行编译Xamarin 项目

Xamarin 平台: 
  • C# language – 使用C#语言构建应用程序
  • Mono .NET framework – 微软的跨平台框架
  • Compiler – 根据不同平台生成不同产品的编译器
  • IDE tools – 集成开发环境,包含了创建,构建,部署,编译等。
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. 

先学习下Android的编译过程,可以对比下java语言开发的Android应用程序: 

java开发的Android应用程序编译执行过程:  
Java ---(JavaC)----> .class ---> JVM load class ---> main 方法执行 

Xamarin平台C#应用程序编译执行过程: 
C#(.cs文件) ---(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 编译打包可执行程序: 
官网介绍: 
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. 在Xamarin创建的工程目录里找到后缀为csproj 的文件 XXX.csproj 
  • 3. 找到Mono提供的MSBuild.exe 
  • 4. 打开命令行,执行命令编译打包: 
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"  /t:SignAndroidPackage Path\To\Your\XXX.csproj  

打包完成后可以看到工程的\bin\Debug 文件夹下找到签名和未签名的apk 
如果需要打包Release版本可以加上字段 /p:Configuration=Release 


备注:以下是我寻找到Mono提供的MSBuild.exe的方法:打开 XXX.csproj 寻找 <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> 在文件夹里搜索 Xamarin.Android.CSharp.targets 搜索到在MSBuild同级目录里找到了 C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe 


参考链接: 

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 命令: 
https://msdn.microsoft.com/en-us/library/ms164311.aspx 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值