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. JDE 增加合计列

  2. 0517Scrum项目4.0

    一.任务看板: 二.任务认领情况: 冯铭杰:界面的设置和部分功能的实现: 梁毅乾:四则运算的功能实现以及代码的维护: 陈施恩:监督小组成员的工作进度,以及代码的编写: 张俊毅:四则运算的算术随机产生: ...

  3. 使用Maven构建RichFaces 4.x项目

    使用Maven构建RichFaces 4.x项目 目录 开始之前 第一步 - 创建Maven项目 第二布 - 添加依赖文件 第三步 - 配置RichFaces 第四步 - 创建显示页面 开始之前 本文 ...

  4. log4net.NoSql +ElasticSearch 实现日志记录

    前言: 前两天在查找如何扩展log4net的日志格式时找到一个开源项目Log4net.NoSql,它通过扩展Appender实现了把日志输出到ElasticSearch里面.顺藤摸瓜,发现涉及的项目还 ...

  5. qml 封装技巧-利用数据来进行适配

    Text属于用的频率比较高而且需要定义的地方又比较多的地方,看一下如下的把Text封装成Label进行使用. 使用的例子: Label { id: titleLabel anchors { left: ...

  6. win7(64)位下WinDbg64调试VMware10下的win7(32位)

    win7(64)位下WinDbg64调试VMware10下的win7(32位) 一 Windbg32位还是64位的选择 参考文档<Windbg 32位版本和64位版本的选择> http:/ ...

  7. 4、android BroadcastReceiver详细用法

    BroadcastReceiver也就是“广播接收者”的意思,顾名思义,它就是用来接收来自系统和应用中的广播. 在Android系统中,广播体现在方方面面,例如当开机完成后系统会产生一条广播,接收到这 ...

  8. Android Studio的一些快捷键

    以下这些也是百度的其他人整理的.后面有新的会加进来. AS的快捷键容易和QQ,微信等冲突,可以手动关掉或者修改其他软件的热键 Ctrl+G / Ctrl+Alt+Shift+G:查询变量或者函数或者类 ...

  9. 标准IO的简单应用,动静态库,读取系统时间并打印,模拟ls -l功能

    2015.2.27星期五,小雨 标准IO实现的复制功能: #include <stdio.h>#include <errno.h> #define N 64 int main( ...

  10. Ubuntu安装gfortran

    命令行运行 sudo apt-get install gfortran