Câu hỏi phỏng vấn Xamarin
Câu hỏi

What is the difference between PCL & _Shared Project?

Câu trả lời

Difference Between Portable Class Library (PCL) and Shared Project in Xamarin

When developing cross-platform applications using Xamarin, developers often need to share code across different platforms such as iOS, Android, and UWP. Two primary methods for sharing code are Portable Class Libraries (PCL) and Shared Projects. Here are the key differences between them:

Portable Class Library (PCL)

  1. Compilation and Output:

    • PCLs are compiled into a stand-alone assembly (DLL) that can be referenced by other projects. This means the PCL is a precompiled library that is included in the final application as a binary[1][3][7].
  2. API Availability:

    • When creating a PCL, you select the target platforms, and the PCL will only allow access to APIs that are available across all selected platforms. This ensures compatibility but can limit the available APIs[1][3][4].
  3. Profiles:

    • PCLs use profiles to define the set of APIs available. Each profile corresponds to a combination of target platforms, and the more platforms you support, the fewer APIs you can use. This can make it challenging to find the right profile that supports all required platforms[1][3].
  4. Usage:

    • PCLs are suitable for writing platform-agnostic code, such as business logic, data models, and service calls. They are less suitable for platform-specific implementations[1][3][4].
  5. XAML Support:

    • PCLs support XAML, which is beneficial for Xamarin.Forms projects where XAML is used for defining the UI[1][2].

Shared Project

  1. Compilation and Output:

    • Shared Projects are not compiled into a separate assembly. Instead, the code in a Shared Project is included directly into the referencing projects at compile time. This means the same source code is compiled as part of each platform-specific project[1][3][7].
  2. API Availability:

    • Shared Projects allow access to all APIs of the target platform. This means you can use platform-specific APIs directly within the shared code, but you need to use conditional compilation to handle platform-specific code[1][3][4].
  3. Conditional Compilation:

    • Shared Projects often require the use of compiler directives (e.g., #if, #endif) to include or exclude code based on the target platform. This can make the code harder to maintain and read[1][3][4].
  4. Usage:

    • Shared Projects are useful for sharing code that needs to interact with platform-specific APIs or for small projects where the overhead of managing multiple projects is not justified[1][3][4].
  5. XAML Support:

    • Shared Projects do not provide IntelliSens...
middle

middle

Gợi ý câu hỏi phỏng vấn

senior

What is the difference between Entry and Editor in Xamarin.Forms?

senior

What is Xamarin.Essentials ?

senior

What is MVVM Cross?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào