从 Visual Studio 2017 15.5.1 开始,如何使用 PCL 创建 Xamarin.Forms 项目以定位最低 Android KitKat (API 19) 现已过时? [英] As of Visual Studio 2017 15.5.1, How Does One Create a Xamarin.Forms Project to Target Minimum Android KitKat (API 19) with PCL now obsolete?

查看:24
本文介绍了从 Visual Studio 2017 15.5.1 开始,如何使用 PCL 创建 Xamarin.Forms 项目以定位最低 Android KitKat (API 19) 现已过时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在不使用共享项目"选项的情况下创建面向最低版本 Android Kitkat (API 19) 的 Xamarin.Forms 项目.

.Net 标准库不是一个选项,因为

有人指出,PCL 现在已在 Xamarin 论坛 上弃用,并且也在 Visual Studio 开发者社区

关键支持问题:

  1. 在最新的 Vs 2017 中,Xamarin.Forms 是否仍然可以实现 PCL?以及如何?
  2. 如果是,创建基于 PCL 的 Xamarin.Forms 项目的步骤是什么,是否有任何开源模板来引导这个项目?
  3. 如果否,这是否意味着我只能使用共享项目代码共享策略/模板支持带有 Xamarin.Forms 的 Android KitKat?

解决方案

  • Forms 支持 Android 4.0.3 (API 15) 及更高版本,您混淆了目标框架"(compileSdkVersion)和目标 Android 版本"(targetSdkVersion)与最低 Android 版本"(minSdkVersion).

    • 您的Xamarin.Form 项目必须使用 Nougat/7.0 (MonoAndroid7.0) 或以上的目标框架但是可以定位到最低 4.0.3/IceCreamSandwich 版本.

      • 注意:最新版本的 Forms 需要 8.0 的目标框架
    • Xamarin 有一个很好的指南,解释了这些东西从 Android 到 Xamarin.Android

  • Microsoft 完全删除了用于创建基于 PCL 的库的模板选项

    • PCL 项目仍然构建良好

    • NetStandard 是唯一的未来,PCL 已死,等等......

    • 恕我直言,这是一个重大变化,因为我的很多客户还没有准备好转换为 NetStd,而且仍然存在 NetStd 错误(主要是边缘情况)

    • 仍然需要创建一个 PCL 库,获取现有项目并复制、剥离和重命名它...或者自己创建 .csproj(参见基本的 .csproj).

基本配置文件111 PCL .csproj:

I want to know how to create a Xamarin.Forms Project that targets minimum version of Android Kitkat (API 19), without using the Shared Project option.

.Net Standard Library is not an option since the minimum supported Android version is Nougat. A large percentage of my target users (more than 40%) still uses phones with an Android version lower than Nougat.

In Visual Studio 15.5.1 or greater, no PCL option is provided under the Code Sharing Strategy Section in creating a new Xamarin.Forms project when using the Cross-Platform App template.

It was noted that PCL is now deprecated on Xamarin's Forum and also on the Visual Studio Developer Community

Key Supporting Questions:

  1. With the latest Vs 2017, is PCL even still possible with Xamarin.Forms? And How?
  2. If Yes, What are the steps to create a PCL-Based Xamarin.Forms Project and are there any open-soured templates to bootstrap this?
  3. If No, Does this mean I can only support Android KitKat with Xamarin.Forms using the Shared-Project Code Sharing strategy/template?

解决方案

  • Forms supports Android 4.0.3 (API 15) and higher, you are confusing the "Target Framework" (compileSdkVersion) for the "Target Android Version" ( targetSdkVersion) vs the "Minimum Android Version" (minSdkVersion).

    • Your Xamarin.Form project has to use the target framework of Nougat/7.0 (MonoAndroid7.0) or above but can target the minimum of 4.0.3/IceCreamSandwich version.

      • Note: The latest version of Forms required a target framework of 8.0
    • Xamarin has a great guide that explains how those things relate from Android to Xamarin.Android

  • Microsoft completely removed the template option to create PCL-based libraries

    • PCL projects still build fine

    • NetStandard is the only future, PCLs are dead, etc, etc...

    • IMHO this was breaking change as a lot of my clients are not ready to convert to NetStd and there are still NetStd bugs floating around (edge cases mostly)

    • Still need to create a PCL library, grab an existing project and copy, strip and rename it... or create the .csproj yourself (see basic .csproj).

A Basic Profile111 PCL .csproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{C38DBA87-39CB-4FD5-B409-6D19E6ED54C8}</ProjectGuid>
    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <UseMSBuildEngine>true</UseMSBuildEngine>
    <OutputType>Library</OutputType>
    <RootNamespace>PCLTemplate</RootNamespace>
    <AssemblyName>PCLTemplate</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>binDebug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Optimize>true</Optimize>
    <OutputPath>binRelease</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="MyClass.cs" />
    <Compile Include="PropertiesAssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath32)MicrosoftPortable$(TargetFrameworkVersion)Microsoft.Portable.CSharp.targets" />
</Project>

这篇关于从 Visual Studio 2017 15.5.1 开始,如何使用 PCL 创建 Xamarin.Forms 项目以定位最低 Android KitKat (API 19) 现已过时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆