Skip to content

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Mar 23, 2021

In .NET 6, we set a $(_XATargetFrameworkDirectories) MSBuild
property to be used throughout the legacy MSBuild targets:

_XATargetFrameworkDirectories =
    ...\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.2.21154.6\ref\net6.0\
    ...\dotnet\packs\Microsoft.Android.Ref\11.0.200-ci.main.148\ref\net6.0\

However, when testing a new workload for .NET Maui we hit the error:

error XARSD7004: System.ArgumentException: `...\dotnet\packs\Microsoft.Maui.Controls.Ref\0.0.1-alpha1\ref\net6.0` must be a directory! (Parameter 'frameworkDirectories')
error XARSD7004:    at Xamarin.Android.Tools.AndroidVersions..ctor(IEnumerable`1 frameworkDirectories) in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/AndroidVersions.cs:line 30
error XARSD7004:    at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshSupportedVersions(String[] referenceAssemblyPaths)
error XARSD7004:    at Xamarin.Android.Tasks.ResolveSdks.RunTask()
error XARSD7004:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

The net6.0 directory does not exist, because the assemblies are in
platform-specific directories such as net6.0-android30.0,
net6.0-ios13.6, net6.0-maccatalyst13.5, etc.

The problem with the current logic:

<_ResolveSdksFrameworkRefAssemblyPaths Include="@(ResolvedTargetingPack->'%(Path)\ref\%(TargetFramework)')" Condition=" '@(ResolvedTargetingPack)' == '@(FrameworkReference)' and '%(Identity)' != '' " />

The %(TargetFramework) item metadata is net6.0, but we somehow
need to use the net6.0-android30.0 directory.

The ResolvedTargetingPackAssets MSBuild target from the dotnet/sdk
sets @(Reference) for each assembly that comes from a "targeting
pack". The @(Reference) item group that contains item metadata such
as:

...\dotnet\packs\Microsoft.Maui.Controls.Ref\0.0.1-alpha1\ref\net6.0-android30.0\Microsoft.Maui.dll
    AssemblyVersion = 1.0.0.0
    ExternallyResolved = true
    FileVersion = 1.0.0.0
    FrameworkReferenceName = Microsoft.Maui.Controls
    FrameworkReferenceVersion = 0.0.1-alpha1
    NuGetPackageId = Microsoft.Maui.Controls.Ref
    NuGetPackageVersion = 0.0.1-alpha1
    Private = false
    PublicKeyToken =

If we grab directories of each item with %(FrameworkReferenceName)
filled out, which means they come from a "targeting pack":

<_ResolveSdksFrameworkRefAssemblyPaths Include="@(Reference->'%(RootDir)%(Directory)')" Condition=" '%(Reference.FrameworkReferenceName)' != '' " />

Then as long as we use ->Distinct(), we now get correct values for
$(_XATargetFrameworkDirectories):

_XATargetFrameworkDirectories =
    ...\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.2.21154.6\ref\net6.0\
    ...\dotnet\packs\Microsoft.Android.Ref\11.0.200-ci.main.148\ref\net6.0\
    ...\dotnet\packs\Microsoft.Maui.Controls.Ref\0.0.1-alpha1\ref\net6.0-android30.0\

After this change, I'm able to build projects with the .NET Maui
workload targeting Android. I think this logic should be correct going
forward in .NET 6.

@jonathanpeppers jonathanpeppers force-pushed the dotnet-targetingpack-directories branch from 5203df6 to dfdabdf Compare March 23, 2021 16:23
@jonathanpeppers jonathanpeppers marked this pull request as draft March 23, 2021 20:37
@jonathanpeppers
Copy link
Member Author

This is breaking, let me see what changed:

ILLink : error IL1019: Value used with '--custom-data' has to be in the KEY=VALUE format

Maybe we are picking up an extra directory now?

In .NET 6, we set a `$(_XATargetFrameworkDirectories)` MSBuild
property to be used throughout the legacy MSBuild targets:

    _XATargetFrameworkDirectories =
        ...\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.2.21154.6\ref\net6.0\
        ...\dotnet\packs\Microsoft.Android.Ref\11.0.200-ci.main.148\ref\net6.0\

However, when testing a new workload for .NET Maui we hit the error:

    error XARSD7004: System.ArgumentException: `...\dotnet\packs\Microsoft.Maui.Controls.Ref\0.0.1-alpha1\ref\net6.0` must be a directory! (Parameter 'frameworkDirectories')
    error XARSD7004:    at Xamarin.Android.Tools.AndroidVersions..ctor(IEnumerable`1 frameworkDirectories) in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/AndroidVersions.cs:line 30
    error XARSD7004:    at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshSupportedVersions(String[] referenceAssemblyPaths)
    error XARSD7004:    at Xamarin.Android.Tasks.ResolveSdks.RunTask()
    error XARSD7004:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17

The `net6.0` directory does not exist, because the assemblies are in
platform-specific directories such as `net6.0-android30.0`,
`net6.0-ios13.6`, `net6.0-maccatalyst13.5`, etc.

The problem with the current logic:

    <_ResolveSdksFrameworkRefAssemblyPaths Include="@(ResolvedTargetingPack->'%(Path)\ref\%(TargetFramework)')" Condition=" '@(ResolvedTargetingPack)' == '@(FrameworkReference)' and '%(Identity)' != '' " />

The `%(TargetFramework)` item metadata is `net6.0`, but we somehow
need to use the `net6.0-android30.0` directory.

The `ResolvedTargetingPackAssets` MSBuild target from the dotnet/sdk
sets `@(Reference)` for each assembly that comes from a "targeting
pack". The `@(Reference)` item group that contains item metadata such
as:

    ...\dotnet\packs\Microsoft.Maui.Controls.Ref\0.0.1-alpha1\ref\net6.0-android30.0\Microsoft.Maui.dll
        AssemblyVersion = 1.0.0.0
        ExternallyResolved = true
        FileVersion = 1.0.0.0
        FrameworkReferenceName = Microsoft.Maui.Controls
        FrameworkReferenceVersion = 0.0.1-alpha1
        NuGetPackageId = Microsoft.Maui.Controls.Ref
        NuGetPackageVersion = 0.0.1-alpha1
        Private = false
        PublicKeyToken =

If we grab directories of each item with `%(FrameworkReferenceName)`
filled out, which means they come from a "targeting pack":

    <_ResolveSdksFrameworkRefAssemblyPaths Include="@(Reference->'%(RootDir)%(Directory)')" Condition=" '%(Reference.FrameworkReferenceName)' != '' " />

Then as long as we use `->Distinct()`, we now get correct values for
`$(_XATargetFrameworkDirectories)`:

    _XATargetFrameworkDirectories =
        ...\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.2.21154.6\ref\net6.0\
        ...\dotnet\packs\Microsoft.Android.Ref\11.0.200-ci.main.148\ref\net6.0\
        ...\dotnet\packs\Microsoft.Maui.Controls.Ref\0.0.1-alpha1\ref\net6.0-android30.0\

After this change, I'm able to build projects with the .NET Maui
workload targeting Android. I think this logic should be correct going
forward in .NET 6.
@jonathanpeppers jonathanpeppers force-pushed the dotnet-targetingpack-directories branch from dfdabdf to 42f2b9a Compare March 24, 2021 14:04
@jonathanpeppers jonathanpeppers marked this pull request as ready for review March 24, 2021 14:04
@jonathanpeppers
Copy link
Member Author

The issue was the trailing \ was escaping the ":

XATargetFrameworkDirectories="C:\Users\AzDevOps\android-toolchain\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.3.21167.1\ref\net6.0\;C:\Users\AzDevOps\android-toolchain\dotnet\packs\Microsoft.Android.Ref\11.0.200-ci.pr.gh5767.171\ref\net6.0\"

While this one works:

XATargetFrameworkDirectories="C:\src\maui\bin\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0-preview.2.21154.6\ref\net6.0;C:\src\maui\bin\dotnet\packs\Microsoft.Android.Ref\11.0.200-ci.main.148\ref\net6.0"

I trimmed the trailing slash, which seems to fix it.

@jonpryor jonpryor merged commit 4beecfb into dotnet:main Mar 24, 2021
@jonathanpeppers jonathanpeppers deleted the dotnet-targetingpack-directories branch March 24, 2021 19:35
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 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