Skip to content

Conversation

@jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented May 7, 2020

Context: https://github.com/xamarin/net5-samples/blob/d525d8a2d60700f52f86372c47e83d646d800aa4/Directory.Android.targets

Currently, .NET 5 will not restore existing Xamarin.Android NuGet
packages. It does not know to map netcoreapp5.0 to
MonoAndroid10.0, MonoAndroid9 etc.

We'll need to work around this until this lands:

To get a Xamarin.Forms project building & running at all in
xamarin/net5-samples, I had to:

  1. Change $(AssetTargetFallback)
  2. Write an MSBuild target to replace any instances of
    netstandard2.0\Xamarin.Forms.Platform.dll with
    MonoAndroid10.0\Xamarin.Forms.Platform.dll.
  3. Add additional platform-specific assemblies in
    $(PkgXamarin_Forms)\lib\MonoAndroid10.0\

There are still some issues with this:

  1. You get a lot of NU1701 warnings due to $(AssetTargetFallback).
  2. Due to: https://github.com/NuGet/docs.microsoft.com-nuget/issues/1955
    You have to manually list every transitive dependency, which
    totals around ~36 packages for AndroidX.

These drawbacks make it completely impractical to run some subset of
our existing MSBuild tests on .NET 5. We would have to list the entire
tree of <PackageReference/> for every test.

Since we might be waiting a bit of time for this, I have been able to
come up with some workarounds to solve these problems for now:

  1. Add a Microsoft.Android.Sdk.NuGet.targets with workarounds that
    we will completely remove down the road (I hope!).
  2. Use $(PackageTargetFallback) instead of $(AssetTargetFallback).
    It does not emit NU1701 warnings, and transitive dependencies
    work! It is a deprecated MSBuild property, but should be fine as a
    workaround.
  3. Write a _FixupNuGetReferences MSBuild target that runs after
    ResolvePackageAssets. A <FixupNuGetReferences/> MSBuild task
    will remove any netstandard2.0 assemblies where platform-specific
    ones exist. It also needs to add platform-specific assemblies that
    are missing.

With this in place, a Xamarin.Forms .csproj with no hacks works!

 <Project Sdk="Microsoft.Android.Sdk">
   <PropertyGroup>
    <TargetFramework>netcoreapp5.0</TargetFramework>
    <OutputType>Exe</OutputType>
   </PropertyGroup>
   <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.5.0.617" />
   </ItemGroup>
 </Project>

I created a new XamarinFormsXASdkProject class for use in our
existing .NET 5 MSBuild tests.

Other changes:

@jonathanpeppers jonathanpeppers requested a review from pjcollins May 8, 2020 13:06
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 8, 2020 13:06
Context: https://github.com/xamarin/net5-samples/blob/d525d8a2d60700f52f86372c47e83d646d800aa4/Directory.Android.targets

Currently, .NET 5 will not restore *existing* Xamarin.Android NuGet
packages. It does not know to map `netcoreapp5.0` to
`MonoAndroid10.0`, `MonoAndroid9` etc.

We'll need to work around this until this lands:

* NuGet/NuGet.Client#3339

To get a Xamarin.Forms project building & running *at all* in
`xamarin/net5-samples`, I had to:

1. Change `$(AssetTargetFallback)`
2. Write an MSBuild target to replace any instances of
   `netstandard2.0\Xamarin.Forms.Platform.dll` with
   `MonoAndroid10.0\Xamarin.Forms.Platform.dll`.
3. Add additional platform-specific assemblies in
   `$(PkgXamarin_Forms)\lib\MonoAndroid10.0\`

There are still some issues with this:

1. You get a lot of `NU1701` warnings due to `$(AssetTargetFallback)`.
2. Due to: https://github.com/NuGet/docs.microsoft.com-nuget/issues/1955
   You have to manually list *every* transitive dependency, which
   totals around ~36 packages for AndroidX.

These drawbacks make it completely impractical to run some subset of
our existing MSBuild tests on .NET 5. We would have to list the entire
tree of `<PackageReference/>` for every test.

Since we might be waiting a bit of time for this, I have been able to
come up with some workarounds to solve these problems for now:

1. Add a `Microsoft.Android.Sdk.NuGet.targets` with workarounds that
   we will completely remove down the road (I hope!).
2. Use `$(PackageTargetFallback)` instead of `$(AssetTargetFallback)`.
   It does not emit `NU1701` warnings, and transitive dependencies
   work! It is a deprecated MSBuild property, but should be fine as a
   workaround.
3. Write a `_FixupNuGetReferences` MSBuild target that runs after
   `ResolvePackageAssets`. A `<FixupNuGetReferences/>` MSBuild task
   will remove any `netstandard2.0` assemblies where platform-specific
   ones exist. It also needs to add platform-specific assemblies that
   are missing.

With this in place, a Xamarin.Forms `.csproj` with no hacks works!

   <Project Sdk="Microsoft.Android.Sdk">
     <PropertyGroup>
      <TargetFramework>netcoreapp5.0</TargetFramework>
      <OutputType>Exe</OutputType>
     </PropertyGroup>
     <ItemGroup>
      <PackageReference Include="Xamarin.Forms" Version="4.5.0.617" />
     </ItemGroup>
   </Project>

I created a new `XamarinFormsXASdkProject` class for use in our
existing .NET 5 MSBuild tests.

Other changes:

* `$(XamarinAndroidVersion)` needs to be filled out for the AndroidX
  MSBuild targets:
  https://github.com/xamarin/XamarinAndroidXMigration/blob/ea130ca0d0e9b3e20edccec02364f36da11ada6b/source/Xamarin.AndroidX.Migration/BuildTasks/Xamarin.AndroidX.Migration.targets#L107
* `$(RuntimeIdentifier)` should have a default value for application
  projects.
* Some tweaks to make `XASdkProject` more flexible.
* `Xamarin.ProjectTools.DotNetStandard` projects now support
  `<Import/>`.
* Added AndroidX-compatible `Tabbar.xml` and `Toolbar.xml`
Copy link
Contributor

@dellis1972 dellis1972 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok. Made a comment about FixupNuGetReferences though.

@dellis1972 dellis1972 merged commit b67b545 into dotnet:master May 12, 2020
@jonathanpeppers jonathanpeppers deleted the net5-nuget-hacks branch May 12, 2020 15:29
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 2, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as xamarin-android:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 3, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as xamarin-android:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 3, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as `xamarin-android`:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53

I updated the `README.md` and our Azure DevOps build pipeline.
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 3, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as `xamarin-android`:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53

I updated the `README.md` and our Azure DevOps build pipeline.
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 3, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as `xamarin-android`:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53

I updated the `README.md` and our Azure DevOps build pipeline.
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 3, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as `xamarin-android`:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53

I updated the `README.md` and our Azure DevOps build pipeline.
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 3, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as `xamarin-android`:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53

I updated the `README.md` and our Azure DevOps build pipeline.
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Jun 4, 2020
Fixes: #16

`$(TargetFramework)` should be `net5.0` now.

Android has the following fixes:

* dotnet/android#4663
* dotnet/android#4692

This enables several workarounds to be removed.

Also use the same .NET 5 build as `xamarin-android`:

https://github.com/xamarin/xamarin-android/blob/cde7b79dce48d9f3fdfc396641a01fb27d165042/build-tools/automation/azure-pipelines.yaml#L53

I updated the `README.md` and our Azure DevOps build pipeline.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants