Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Classic Item Groups? #40

Open
jonpryor opened this issue Jul 12, 2022 · 2 comments
Open

Classic Item Groups? #40

jonpryor opened this issue Jul 12, 2022 · 2 comments

Comments

@jonpryor
Copy link
Member

From the description:

Starting from a .NET 6 project, adds the ability to target legacy Xamarin target frameworks such as monoandroid11.0 or xamarin.ios10.

How much additional work should be expected? Let's try this out:

dotnet new android -n xls-def-net6
cd xls-def-net6
sed -i .bk 's,^<Project Sdk="Microsoft.NET.Sdk">,<Project Sdk="Xamarin.Legacy.Sdk/0.1.0-alpha2">,g' xls-def-net6.csproj
dotnet build

Builds with $(TargetFramework)=net6.0-android. Now let's multitarget:

sed -i .bk2 's,<TargetFramework>net6.0-android</TargetFramework>,<TargetFrameworks>monoandroid12.0;net6.0-android</TargetFrameworks>,g' xls-def-net6.csproj
dotnet build

This -- predictably in retrospect -- fails to build:

MainActivity.cs(1,1): error CS8400: Feature 'file-scoped namespace' is not available in C# 8.0. Please use language version 10.0 or greater.

OK, so we update xls-def-net6.csproj so that $(ImplicitUsings)=disable, update MainActivity.cs so that it compiles without implicit usings, and…

MainActivity.cs(14,33): error CS0117: 'Resource' does not contain a definition for 'Layout'

Thus, the question: "how much" work is expected to target a Classic SDK when starting from .NET 6?

I can get this "default .NET 6. project" to build monoandroid12.0 by adding:

  <ItemGroup>
    <AndroidResource Include="Resources\**\*" />
    <AndroidResource Remove="Resources\AboutResources.txt" />
  </ItemGroup>

Should this be expected? Should we add some default item groups for Classic?

What about creating .apk/.aab files? dotnet build -t:SignAndroidPackage doesn't work:

xls-def-net6.csproj : error MSB4057: The target "SignAndroidPackage" does not exist in the project.

You can set $(AndroidBuildApplicationPackage)=True:

% dotnet build -p:AndroidBuildApplicationPackage=True
% ls -l bin/Debug/*/*.apk
-rw-r--r--  1 jon  staff  13959540 Jul 12 15:20 bin/Debug/monoandroid12.0/com.companyname.xls_def_net6-Signed.apk
-rw-r--r--  1 jon  staff  13945727 Jul 12 15:20 bin/Debug/monoandroid12.0/com.companyname.xls_def_net6.apk
-rw-r--r--  1 jon  staff   2493165 Jul 12 15:18 bin/Debug/net6.0-android/com.companyname.xls_def_net6-Signed.apk
-rw-r--r--  1 jon  staff   2482972 Jul 12 15:17 bin/Debug/net6.0-android/com.companyname.xls_def_net6.apk

Is this expected?

@jonpryor
Copy link
Member Author

To some extent, instead of "Start from a .NET 6 project, add Classic builds", a "modified opposite" perspective may be more accurate: start with a Classic (long-form) Project, then hand-edit your way to Classic + .NET 6 multitargeting. With Classic as a starting point, @(AndroidResource)/etc. will already be used, thus ensuring that Classic continues to build.

@jonathanpeppers
Copy link
Member

Given Xamarin.Legacy.Sdk only has ~5k downloads, maybe it's not worth looking into these? A lot of it appears to be C# 10 changes.

@jonpryor did you try MSBuild.Sdk.Extras, to see if they fare any better.

I would also test a class library, as I'm not sure the point of multi-targeting an "app" project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants