When you first created the Hello solution in Visual Studio, you had a choice of two application templates:
  Blank App (Xamarin.Forms Portable)
  Blank App (Xamarin.Forms Shared)
In Xamarin Studio, the choice is embodied in a pair of radio buttons:
  Use Portable Class Library
  Use Shared Library
The first option creates a Portable Class Library (PCL), whereas the second creates a Shared Asset Project (SAP) consisting only of shared code files. The original Hello solution used the PCL template. Now let’s create a second solution named HelloSap with the SAP template. 

原文

  当我们在VS中创建Hello解决方案的时候,可以选择两种类型的项目模板。第一个选项创建的是可移植的类库(PCL),而第二个创建的是共享的资源项目(SAP),仅仅包含一个共享文件。之前的使用的是PCL模板,下面使用SAP模板创建一个解决方案HelloSap。

As you’ll see, everything looks pretty much the same, except that the HelloSap project itself contains only one item: the App.cs file.  

With both the PCL and SAP approaches, code is shared among the five applications, but in decidedly different ways: With the PCL approach, all the common code is bundled into a dynamic-link library that each application project references and binds to at run time. With the SAP approach, the common code files are effectively included with each of the five application projects at build time. By default, the SAP has only a single file named App.cs, but effectively it’s as if this HelloSap project did not exist and instead there were five different copies of this file in the five application projects. 

Some subtle (and not-so-subtle) problems can manifest themselves with the shared library approach: 

The iOS and Android projects have access to pretty much the same version of .NET, but it is not the same version of .NET that the Windows projects use. This means that any .NET classes accessed by the shared code might be somewhat different depending on the platform. As you’ll discover later in this book, this is the case for some file I/O classes in the System.IO namespace. 

You can compensate for these differences by using C# preprocessor directives, particularly #if and #elif. In the projects generated by the Xamarin.Forms template, the various application projects define symbols that you can use with these directives. 

原文

  创建结束后,可以看到HelloSap解决方案中,除了HelloSap这个项目之外,其他的几个项目都和我们使用PCL模板创建出来的类似。

  不管你使用的是PCL还是SAP,都会被另外几个项目所引用,但是二者有着不同之处。如果使用PCL,所有的公共代码是生成到一个动态链接库(dll)中去,然后其他项目在运行的时候去引用这个dll。然而,SAP方法中,在编译的时候公共代码直接包含在其他的几个项目中了。默认情况下SAP项目只有一个cs文件,如果HelloSap这个项目不存在,完全可以在其他项目中包含这个cs文件来代替这个项目。

...

Most of the programs in this book use the PCL approach. This is the recommended approach for Xamarin.Forms and is preferred by many programmers who have been working with Xamarin.Forms for a while. However, the SAP approach is also supported and definitely has its advocates as well. Programs within these pages that demonstrate the SAP approach always contain the letters Sap at the end of their names, such as the HelloSap program. 

But why choose? You can have both in the same solution. If you’ve created a Xamarin.Forms solution with a Shared Asset Project, you can add a new PCL project to the solution by selecting the Class Library (Xamarin.Forms Portable) template. The application projects can access both the SAP and PCL, and the SAP can access the PCL as well. 

原文

  这本书的大部分示例程序使用的是PCL方法,它是Xamarin.Froms推荐的方法,并且是多数开发者一直所使用的。但是,这两个项目可以同时包含在一个解决方案中。

PCL还是SAP?的更多相关文章

  1. 使用Xamarin.Forms平台开发移动应用指南

    下载书:链接: http://pan.baidu.com/s/1c29H9KG 密码: 7esm 注:捣鼓虚拟机把Hyper-V关闭,后来Xamarin搞挂了,所以暂停翻译. 第1章 Xamarin. ...

  2. 使用C#和.NET的原因

    早在2000年6月,微软公布.NET之后不久,Ximian公司诞生了一个开源项目叫做Mono,运行在Linux环境下面的C#编译器和.NET Framework.十年后,在2011年,Ximian的创 ...

  3. Xamarin.Forms介绍

    On May 28, 2014, Xamarin introduced Xamarin.Forms, which allows you to write user-interface code tha ...

  4. 在Label中显示一段文字

    Let’s create a new Xamarin.Forms PCL solution, named Greetings, using the same process described abo ...

  5. Xamarin.Forms入门学习路线

    Xamarin 介绍 Xamarin是一套跨平台解决方案,目的是使用C#语言创造原生的iOS,Android,Mac和Windows应用. Xamarin的三个优势: Xamarin App拥有原生A ...

  6. Xamarin.Forms 调用 腾讯地图SDK

    Xamarin.Forms研究了好一段时间了,最近一直在学习中,想尝试一下调用其他的SDK,就如腾讯地图SDK(申请容易). 完成此次项目得感谢以下链接: http://www.cnblogs.com ...

  7. 基于传统方法点云分割以及PCL中分割模块

      之前在微信公众号中更新了以下几个章节 1,如何学习PCL以及一些基础的知识 2,PCL中IO口以及common模块的介绍 3,PCL中常用的两种数据结构KDtree以及Octree树的介绍    ...

  8. Xamarin+Prism开发详解一:PCL跨平台类库与Profile的关系

    在[Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用]中提到过以下错误,不知道大伙还记得不: 无法安装程序包"Microsoft.Identity.Client 1.0. ...

  9. SAP CRM 性能小技巧

    导言 本页面打算收集SAP CRM实施中可以用于避免性能问题的注意事项,重要的事项会由图标标识. 如果你有其他的技巧想要说出来,别犹豫! 性能注意事项 通用 缓存读取类访问,特别是在性能关键的地方,比 ...

随机推荐

  1. linux 下mysql的启动 、调试、排错

    Linux 下 MySQL 启动与关闭 说明 一.启动 1.1  MySQL 进程 可以用ps 命令查看进程: [root@rac2 ~]# ps -ef|grep mysql root     21 ...

  2. 由ArrayList构造函数源码引出的问题

    ArrayList应该用得很多了.最近看了看其源码,发现有很多细节,如果要我们自己来实现,估计会考虑不到.当然,这些细节跟jdk本身一些实现的bug有关,如果不去深挖,定然是不能发现.本文从Array ...

  3. android baseActivity

    package newdemo.jeno.designdemo.activitynew; import android.os.Bundle;import android.support.annotat ...

  4. java中的包以及内部类的介绍

    1:形式参数和返回值的问题(理解)    (1)形式参数:        类名:需要该类的对象        抽象类名:需要该类的子类对象        接口名:需要该接口的实现类对象    (2)返 ...

  5. 关于async

    以前做项目很少理会async这个属性 今天做项目的时候 由于原来是点击查看按钮进行查看 现在要把需求改成默认进入页面就直接显示内容 我在js加载的时候就需要调用一次查看的点击事件 我在整个js初始加载 ...

  6. UIImagePickerController 获取相片视频

    1.UIImagePickerController的静态方法: imagepicker = [[UIImagePickerController alloc]init];    //UIImagePic ...

  7. python模块之time

    Python中的时间模块. 1.在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素. 2.UTC(Coordinated U ...

  8. 在Hibernate中配置Hilo进行数据绑定测试时出错:org.hibernate.MappingException: Could not instantiate id generator

    在进行学习具体类单表继承时使用hilo类型时总是在调度过程中提示如下信息,无法通过.留下记录备查. 在网上找相关信息, 未解决,详细如下: org.hibernate.MappingException ...

  9. 【LeetCode OJ】Flatten Binary Tree to Linked List

    Problem Link: http://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ The problem is ask ...

  10. 《JavaScript模式》第5章 对象创建模式

    @by Ruth92(转载请注明出处) 第5章:对象创建模式 JavaScript 是一种简洁明了的语言,并没有其他语言中经常使用的一些特殊语法特征,如 命名空间.模块.包.私有属性 以及 静态成员 ...