-
Notifications
You must be signed in to change notification settings - Fork 564
[.NET 5] NuGet workarounds for Xamarin.Forms projects #4663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dd6b497 to
47c2608
Compare
pjcollins
approved these changes
May 11, 2020
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.props
Outdated
Show resolved
Hide resolved
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`
47c2608 to
300c3a8
Compare
dellis1972
reviewed
May 12, 2020
dellis1972
reviewed
May 12, 2020
Contributor
dellis1972
left a comment
There was a problem hiding this 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
approved these changes
May 12, 2020
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.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.0toMonoAndroid10.0,MonoAndroid9etc.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:$(AssetTargetFallback)netstandard2.0\Xamarin.Forms.Platform.dllwithMonoAndroid10.0\Xamarin.Forms.Platform.dll.$(PkgXamarin_Forms)\lib\MonoAndroid10.0\There are still some issues with this:
NU1701warnings due to$(AssetTargetFallback).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:
Microsoft.Android.Sdk.NuGet.targetswith workarounds thatwe will completely remove down the road (I hope!).
$(PackageTargetFallback)instead of$(AssetTargetFallback).It does not emit
NU1701warnings, and transitive dependencieswork! It is a deprecated MSBuild property, but should be fine as a
workaround.
_FixupNuGetReferencesMSBuild target that runs afterResolvePackageAssets. A<FixupNuGetReferences/>MSBuild taskwill remove any
netstandard2.0assemblies where platform-specificones exist. It also needs to add platform-specific assemblies that
are missing.
With this in place, a Xamarin.Forms
.csprojwith no hacks works!I created a new
XamarinFormsXASdkProjectclass for use in ourexisting .NET 5 MSBuild tests.
Other changes:
$(XamarinAndroidVersion)needs to be filled out for the AndroidXMSBuild 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 applicationprojects.
XASdkProjectmore flexible.Xamarin.ProjectTools.DotNetStandardprojects now support<Import/>.Tabbar.xmlandToolbar.xml