Skip to content

Restore "[One .NET] fix GetAndroidDependencies target with --no-restore" #10339

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,18 @@ public abstract class Foo<TVirtualView, TNativeView> : ViewHandler<TVirtualView,
builder.AssertHasNoWarnings ();
}
}

[Test]
public void GetAndroidDependencies()
{
var proj = new XamarinAndroidApplicationProject ();
using var builder = CreateApkBuilder ();
builder.Save (proj);

var dotnet = new DotNetCLI (Path.Combine (Root, builder.ProjectDirectory, proj.ProjectFilePath));

// `dotnet build -t:GetAndroidDependencies --no-restore` should succeed
Assert.IsTrue (dotnet.Build (target: "GetAndroidDependencies", norestore: true), $"{proj.ProjectName} should succeed");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ public bool Restore (string target = null, string runtimeIdentifier = null, stri
return Execute (arguments.ToArray ());
}

public bool Build (string target = null, string runtimeIdentifier = null, string [] parameters = null)
public bool Build (string target = null, string runtimeIdentifier = null, string [] parameters = null, bool norestore = false)
{
var arguments = GetDefaultCommandLineArgs ("build", target, runtimeIdentifier, parameters);
if (norestore)
arguments.Add ("--no-restore");
return Execute (arguments.ToArray ());
}

Expand Down
24 changes: 16 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,31 @@ projects.
</Target>

<PropertyGroup>
<_ResolveSdksDependsOnTargets>ResolveTargetingPackAssets</_ResolveSdksDependsOnTargets>
<_ResolveSdksDependsOnTargets>ProcessFrameworkReferences</_ResolveSdksDependsOnTargets>
</PropertyGroup>

<Target Name="_ResolveSdks" DependsOnTargets="$(_ResolveSdksDependsOnTargets)">
<!-- When using .NET 5, provide a list of paths to the Android and NETCore targeting pack directories, e.g.
`packages\microsoft.android.ref\10.0.100-ci.master.22\ref\net5.0\` and
`C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0-preview.6.20264.1\ref\net5.0\`
See https://github.com/dotnet/sdk/blob/9eeb58e24af894597a534326156d09173d9f0f91/src/Tasks/Microsoft.NET.Build.Tasks/ResolveTargetingPackAssets.cs#L56
-->
<ItemGroup>
<_AndroidApiInfo Include="$(MSBuildThisFileDirectory)..\data\*\AndroidApiInfo.xml" />
<_AndroidApiInfoDirectories Include="@(_AndroidApiInfo->'%(RootDir)%(Directory)')" />
<_ResolveSdksFrameworkRefAssemblyPaths Include="@(Reference->'$([System.String]::Copy('%(RootDir)%(Directory)').TrimEnd('\'))')" Condition=" '%(Reference.FrameworkReferenceName)' != '' " />
<!--
When using .NET 6+, provide the directory containing Mono.Android.dll and System.dll.
Use %(TargetingPack.Path) / %(TargetingPack.PackageDirectory) to get this information.
See: https://github.com/dotnet/sdk/blob/1b4646d2244ffa462e59f10bc752f2ff6f94b569/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets#L79-L93
-->
<_AndroidTargetingPackAssemblyPath
Condition=" '%(TargetingPack.Identity)' == 'Microsoft.NETCore.App' "
Include="$([MSBuild]::ValueOrDefault('%(TargetingPack.Path)', '%(TargetingPack.PackageDirectory)'))\ref\*\System.dll"
/>
Comment on lines +52 to +55
Copy link
Member Author

Choose a reason for hiding this comment

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

This is still not working when inside VS:

image

But it works fine for local/command-line builds.

I'm not seeing anything in the .binlog that mentions the folder: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\10.0.0-preview.7.25379.102

Copy link
Member Author

Choose a reason for hiding this comment

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

Earliest thing is the target we were using before:

image

Copy link
Member Author

Choose a reason for hiding this comment

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

It's weird how one item is blank:

image

<_AndroidTargetingPackAssemblyPath
Condition=" '%(TargetingPack.Identity)' == 'Microsoft.Android' "
Include="$([MSBuild]::ValueOrDefault('%(TargetingPack.Path)', '%(TargetingPack.PackageDirectory)'))\ref\*\Mono.Android.dll"
/>
<_AndroidTargetingPackDirectories Include="@(_AndroidTargetingPackAssemblyPath->'$([System.String]::Copy('%(RootDir)%(Directory)').TrimEnd('\'))')" Condition=" '%(_AndroidTargetingPackAssemblyPath.RootDir)%(_AndroidTargetingPackAssemblyPath.Directory)' != '' " />
</ItemGroup>
<PropertyGroup>
<_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False</_AndroidAllowMissingSdkTooling>
<_XATargetFrameworkDirectories>@(_ResolveSdksFrameworkRefAssemblyPaths->Distinct())</_XATargetFrameworkDirectories>
<_XATargetFrameworkDirectories>@(_AndroidTargetingPackDirectories->Distinct())</_XATargetFrameworkDirectories>
</PropertyGroup>
<ResolveSdks
ContinueOnError="$(_AndroidAllowMissingSdkTooling)"
Expand Down
Loading