Skip to content
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

[build] Target net7.0. #988

Merged
merged 5 commits into from
May 31, 2022
Merged

[build] Target net7.0. #988

merged 5 commits into from
May 31, 2022

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented May 23, 2022

Context: dotnet/android#6598

Update Java.Interop <TargetFrameworks> to use $(DotNetTargetFramework) like XA does. Additionally, bump this value to net7.0.

Much like the previous #986, Mono cannot build with the .NET 7 reference assemblies:

/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets
(1232,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v7.0" were not found. You might be using an 
older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK. 

In order to fix this, the Mac - Mono lane now builds with .NET 7, however the tests are still run with Mono.

Command line utilities will continue to be built with stable net6.0.

Test XA PR to ensure it works with XA: dotnet/android#7028.

@pjcollins
Copy link
Member

Waiting for the latest results for dotnet/android#7028, but I think this should be good to go.

@pjcollins pjcollins marked this pull request as ready for review May 25, 2022 21:15
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;$(DotNetStableTargetFramework)</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

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

I made a thing like $(DotNetStableTargetFramework) in xamarin-android for console apps that are used during our build. Should utilities we ship like class-parse actually build against 7? It is invoked from MSBuild in customer projects, but they should have a .NET 7 SDK.

We can also wait and update these later.

Copy link
Member

Choose a reason for hiding this comment

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

I figured $(DotNetStableTargetFramework) would also be useful in JI for certain projects, but using it more widely was a bit of a hassle. Keeping the tools that XA ships on a stable .NET version gives us the flexibility to not require a system wide .NET 7 install in XA for now. If we bump these to net7.0 XA will require a global net7.0 install, or we'll need to update our build tasks to run the tool with our local dotnet install. I don't mind bumping these to net7.0 now but I didn't see a strong need to do so, but maybe I am not considering something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine with whatever is easiest for now, but we should endeavor to get everything we ship running on .NET 7 previews since that is how our customers will eventually receive it. We need to find any issues caused by .NET 7 before they do. 😁

Copy link
Member

Choose a reason for hiding this comment

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

xamarin-android/main is already running these on .NET 7, they just have a TargetFramework of net6.0.

If you look at a .binlog of one of our MSBuild tests, it's using a local .NET 7 SDK we provision at ./bin/Release/dotnet/dotnet.

These definitely work on 7, because 6 isn't in here at all:

image

image

Copy link
Member

@pjcollins pjcollins May 26, 2022

Choose a reason for hiding this comment

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

I didn't look too closely, but I think the AndroidDotnetToolTask that runs tools like generator and class parse only uses the dotnet that is found in path? In our XA build case where we test out of a "sandboxed" location I think we end running these tools with the latest version installed system wide. We may want to update that task to try to detect and use the dotnet path that the project is being built from, assuming this is the case. I can investigate this further outside of this PR though.

Copy link
Member

Choose a reason for hiding this comment

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

I think there must be some logic when you Process.Start("dotnet") from inside a dotnet process, for example dotnet run just does this:

https://github.com/dotnet/sdk/blob/ad1ca90ad286288970a4ae1ec77e85848fef5a24/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L869-L877

Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure, previous XA PR builds testing these changes had issues running class-parse and other tools because the XA test environments no longer have NET 7 installed system wide. That blob also mentions an old unresolved issue that seems related. I put up dotnet/android#7038 for now, we can discuss this further over there.

I'm going to revert the $(DotNetStableTargetFramework) changes in this PR.

<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;$(DotNetStableTargetFramework)</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

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

Same with this one, should it build for 7?

tools/jcw-gen/jcw-gen.csproj Outdated Show resolved Hide resolved
tools/logcat-parse/logcat-parse.csproj Outdated Show resolved Hide resolved
tools/param-name-importer/param-name-importer.csproj Outdated Show resolved Hide resolved
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

I'm OK to leave some of the projects in here on 6, the only problem would be if we wanted to use a feature of .NET 7? I don't know if the fast, source generator Regex feature, for example, might be useful in generator or class-parse.

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;$(DotNetTargetFramework)</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

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

This "confuses" me, and I'm not sure what's going on. $(DotNetTargetFramework) is net7.0, thus I would expect bin/Debug-net7.0/Xamarin.Android.Tools.Bytecode.dll to be a file that exists after a build.

However, it doesn't exist; instead, I have bin/Debug-net6.0/Xamarin.Android.Tools.Bytecode.dll, which is a copy of the .NET Standard 2.0 build, which is weird.

Meaning, as a consequence of this change, e.g. the net6.0 class-parse.dll now references the .NET Standard 2.0 build of Xamarin.Android.Tools.Bytecode.dll (v0.2.0.11), whereas before this change it referenced the net6.0 build, 7.0.0.7.

In this case that likely doesn't matter, as there's no #if NET in Xamarin.Android.Tools.Bytecode.dll, but if that ever changed…

I suspect what we actually want/need is to instead add a 3rd $(TargetFramework) value in many of these places, instead of replacing net6.0 with net7.0, a'la:

<TargetFrameworks>netstandard2.0;$(DotNetStableTargetFramework);$(DotNetTargetFramework)</TargetFrameworks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or this is a good reason to make everything target net7.0 instead of some things still targeting net6.0.

Copy link
Member

Choose a reason for hiding this comment

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

I've moved everything back to target net7.0.

pjcollins added a commit to pjcollins/android that referenced this pull request May 26, 2022
Context: dotnet/java-interop#988

A recent attempt to update Java.Interop to target net7.0 produced some
test failures on the Xamarin.Android side:

   Using "ClassParse" task from assembly "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Build.Tasks.dll".
   Task "ClassParse" (TaskId:139)
     Task Parameter:ToolPath=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools (TaskId:139)
     Task Parameter:OutputFile=obj/Debug/api.xml.class-parse (TaskId:139)
     Task Parameter:SourceJars=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar (TaskId:139)
     Using: dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll (TaskId:139)
     [class-parse] response file: obj/Debug/class-parse.rsp (TaskId:139)
     --o="obj/Debug/api.xml.class-parse" (TaskId:139)
     "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar" (TaskId:139)
     /Users/runner/.dotnet/dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll "@obj/Debug/class-parse.rsp"  (TaskId:139)
     It was not possible to find any compatible framework version (TaskId:139)
     The framework 'Microsoft.NETCore.App', version '7.0.0-preview.5.22271.4' (x64) was not found. (TaskId:139)
       - The following frameworks were found: (TaskId:139)
           3.1.1 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.3 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.6 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.25 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.2 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.8 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.17 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           6.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
      (TaskId:139)
     You can resolve the problem by installing the specified framework and/or SDK. (TaskId:139)
      (TaskId:139)
     The specified framework can be found at: (TaskId:139)
       - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0-preview.5.22271.4&arch=x64&rid=osx.12-x64 (TaskId:139)
    1:7>/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Bindings.ClassParse.targets(30,5): error MSB6006: "dotnet" exited with code 150. [/Users/runner/work/1/a/TestRelease/05-25_01.03.40/temp/BuildWithExternalJavaLibrary/BuildWithExternalJavaLibraryBinding/BuildWithExternalJavaLibraryBinding.csproj]

Commit ff7f467 removed the need to have a global .NET 7 preview install
to build and test Xamarin.Android.  This appears to expose an issue in
`AndroidDotnetToolTask`, which uses the latest `dotnet` in $PATH to run
some of our tools.  After upgrading some of these tools (class-parse,
generator) to net7.0, we are no longer able to run them as there is no
net7.0 runtime installed globally.

Improve the `AndroidDotnetToolTask` to better handle "sandboxed" .NET
installations by using a full path to `dotnet` if one is found.
pjcollins added a commit to pjcollins/android that referenced this pull request May 26, 2022
Context: dotnet/java-interop#988

A recent attempt to update Java.Interop to target net7.0 produced some
test failures on the Xamarin.Android side:

   Using "ClassParse" task from assembly "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Build.Tasks.dll".
   Task "ClassParse" (TaskId:139)
     Task Parameter:ToolPath=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools (TaskId:139)
     Task Parameter:OutputFile=obj/Debug/api.xml.class-parse (TaskId:139)
     Task Parameter:SourceJars=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar (TaskId:139)
     Using: dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll (TaskId:139)
     [class-parse] response file: obj/Debug/class-parse.rsp (TaskId:139)
     --o="obj/Debug/api.xml.class-parse" (TaskId:139)
     "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar" (TaskId:139)
     /Users/runner/.dotnet/dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll "@obj/Debug/class-parse.rsp"  (TaskId:139)
     It was not possible to find any compatible framework version (TaskId:139)
     The framework 'Microsoft.NETCore.App', version '7.0.0-preview.5.22271.4' (x64) was not found. (TaskId:139)
       - The following frameworks were found: (TaskId:139)
           3.1.1 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.3 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.6 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.25 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.2 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.8 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.17 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           6.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
      (TaskId:139)
     You can resolve the problem by installing the specified framework and/or SDK. (TaskId:139)
      (TaskId:139)
     The specified framework can be found at: (TaskId:139)
       - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0-preview.5.22271.4&arch=x64&rid=osx.12-x64 (TaskId:139)
    1:7>/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Bindings.ClassParse.targets(30,5): error MSB6006: "dotnet" exited with code 150. [/Users/runner/work/1/a/TestRelease/05-25_01.03.40/temp/BuildWithExternalJavaLibrary/BuildWithExternalJavaLibraryBinding/BuildWithExternalJavaLibraryBinding.csproj]

Commit ff7f467 removed the need to have a global .NET 7 preview install
to build and test Xamarin.Android.  This appears to expose an issue in
`AndroidDotnetToolTask`, which uses the latest `dotnet` in $PATH to run
some of our tools.  After upgrading some of these tools (class-parse,
generator) to net7.0, we are no longer able to run them as there is no
net7.0 runtime installed globally.

Improve the `AndroidDotnetToolTask` to better handle "sandboxed" .NET
installations by using a full path to `dotnet` if one is found.
pjcollins added a commit to pjcollins/android that referenced this pull request May 27, 2022
Context: dotnet/java-interop#988

A recent attempt to update Java.Interop to target net7.0 produced some
test failures on the Xamarin.Android side:

   Using "ClassParse" task from assembly "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Build.Tasks.dll".
   Task "ClassParse" (TaskId:139)
     Task Parameter:ToolPath=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools (TaskId:139)
     Task Parameter:OutputFile=obj/Debug/api.xml.class-parse (TaskId:139)
     Task Parameter:SourceJars=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar (TaskId:139)
     Using: dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll (TaskId:139)
     [class-parse] response file: obj/Debug/class-parse.rsp (TaskId:139)
     --o="obj/Debug/api.xml.class-parse" (TaskId:139)
     "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar" (TaskId:139)
     /Users/runner/.dotnet/dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll "@obj/Debug/class-parse.rsp"  (TaskId:139)
     It was not possible to find any compatible framework version (TaskId:139)
     The framework 'Microsoft.NETCore.App', version '7.0.0-preview.5.22271.4' (x64) was not found. (TaskId:139)
       - The following frameworks were found: (TaskId:139)
           3.1.1 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.3 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.6 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.25 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.2 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.8 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.17 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           6.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
      (TaskId:139)
     You can resolve the problem by installing the specified framework and/or SDK. (TaskId:139)
      (TaskId:139)
     The specified framework can be found at: (TaskId:139)
       - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0-preview.5.22271.4&arch=x64&rid=osx.12-x64 (TaskId:139)
    1:7>/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Bindings.ClassParse.targets(30,5): error MSB6006: "dotnet" exited with code 150. [/Users/runner/work/1/a/TestRelease/05-25_01.03.40/temp/BuildWithExternalJavaLibrary/BuildWithExternalJavaLibraryBinding/BuildWithExternalJavaLibraryBinding.csproj]

Commit ff7f467 removed the need to have a global .NET 7 preview install
to build and test Xamarin.Android.  This appears to expose an issue in
`AndroidDotnetToolTask`, which uses the latest `dotnet` in $PATH to run
some of our tools.  After upgrading some of these tools (class-parse,
generator) to net7.0, we are no longer able to run them as there is no
net7.0 runtime installed globally.

Improve the `AndroidDotnetToolTask` to better handle "sandboxed" .NET
installations by using a full path to `dotnet` if one is found.
@jonpryor
Copy link
Member

Context: https://github.com/xamarin/xamarin-android/pull/6598

Update `$(TargetFrameworks)` across the various `.csproj` files to
use `$(DotNetTargetFramework)`, as xamarin/xamarin-android does.
Additionally, set `$(DotNetTargetFramework)`=net7.0 (.NET 7).

Similar to commit e7bacc37, Mono cannot be used to build against
.NET 7 reference assemblies:

	/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1232,5):
	error MSB3971: The reference assemblies for ".NETFramework,Version=v7.0" were not found.
	You might be using an older .NET SDK to target .NET 5.0 or higher.
	Update Visual Studio and/or your .NET SDK.

Fix this by updating the **Mac - Mono** CI job to *build* with .NET 7,
while Mono-focused unit tests are still run with Mono.

Co-authored-by: Peter Collins <[email protected]>

@jonpryor jonpryor merged commit 1bab47d into main May 31, 2022
@jonpryor jonpryor deleted the net7 branch May 31, 2022 19:09
pjcollins added a commit to pjcollins/android that referenced this pull request May 31, 2022
Context: dotnet/java-interop#988

A recent attempt to update Java.Interop to target net7.0 produced some
test failures on the Xamarin.Android side:

   Using "ClassParse" task from assembly "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Build.Tasks.dll".
   Task "ClassParse" (TaskId:139)
     Task Parameter:ToolPath=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools (TaskId:139)
     Task Parameter:OutputFile=obj/Debug/api.xml.class-parse (TaskId:139)
     Task Parameter:SourceJars=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar (TaskId:139)
     Using: dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll (TaskId:139)
     [class-parse] response file: obj/Debug/class-parse.rsp (TaskId:139)
     --o="obj/Debug/api.xml.class-parse" (TaskId:139)
     "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar" (TaskId:139)
     /Users/runner/.dotnet/dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll "@obj/Debug/class-parse.rsp"  (TaskId:139)
     It was not possible to find any compatible framework version (TaskId:139)
     The framework 'Microsoft.NETCore.App', version '7.0.0-preview.5.22271.4' (x64) was not found. (TaskId:139)
       - The following frameworks were found: (TaskId:139)
           3.1.1 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.3 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.6 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.25 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.2 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.8 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.17 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           6.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
      (TaskId:139)
     You can resolve the problem by installing the specified framework and/or SDK. (TaskId:139)
      (TaskId:139)
     The specified framework can be found at: (TaskId:139)
       - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0-preview.5.22271.4&arch=x64&rid=osx.12-x64 (TaskId:139)
    1:7>/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Bindings.ClassParse.targets(30,5): error MSB6006: "dotnet" exited with code 150. [/Users/runner/work/1/a/TestRelease/05-25_01.03.40/temp/BuildWithExternalJavaLibrary/BuildWithExternalJavaLibraryBinding/BuildWithExternalJavaLibraryBinding.csproj]

Commit ff7f467 removed the need to have a global .NET 7 preview install
to build and test Xamarin.Android.  This appears to expose an issue in
`AndroidDotnetToolTask`, which uses the latest `dotnet` in $PATH to run
some of our tools.  After upgrading some of these tools (class-parse,
generator) to net7.0, we are no longer able to run them as there is no
net7.0 runtime installed globally.

Improve the `AndroidDotnetToolTask` to better handle "sandboxed" .NET
installations by using a full path to `dotnet` if one is found.
pjcollins added a commit to pjcollins/android that referenced this pull request May 31, 2022
Context: dotnet/java-interop#988

A recent attempt to update Java.Interop to target net7.0 produced some
test failures on the Xamarin.Android side:

   Using "ClassParse" task from assembly "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Build.Tasks.dll".
   Task "ClassParse" (TaskId:139)
     Task Parameter:ToolPath=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools (TaskId:139)
     Task Parameter:OutputFile=obj/Debug/api.xml.class-parse (TaskId:139)
     Task Parameter:SourceJars=/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar (TaskId:139)
     Using: dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll (TaskId:139)
     [class-parse] response file: obj/Debug/class-parse.rsp (TaskId:139)
     --o="obj/Debug/api.xml.class-parse" (TaskId:139)
     "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/android-support-multidex.jar" (TaskId:139)
     /Users/runner/.dotnet/dotnet /Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/class-parse.dll "@obj/Debug/class-parse.rsp"  (TaskId:139)
     It was not possible to find any compatible framework version (TaskId:139)
     The framework 'Microsoft.NETCore.App', version '7.0.0-preview.5.22271.4' (x64) was not found. (TaskId:139)
       - The following frameworks were found: (TaskId:139)
           3.1.1 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.3 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.6 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           3.1.25 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.2 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.8 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           5.0.17 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
           6.0.5 at [/Users/runner/.dotnet/shared/Microsoft.NETCore.App] (TaskId:139)
      (TaskId:139)
     You can resolve the problem by installing the specified framework and/or SDK. (TaskId:139)
      (TaskId:139)
     The specified framework can be found at: (TaskId:139)
       - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0-preview.5.22271.4&arch=x64&rid=osx.12-x64 (TaskId:139)
    1:7>/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.0-ci.pr.gh7028.23/tools/Xamarin.Android.Bindings.ClassParse.targets(30,5): error MSB6006: "dotnet" exited with code 150. [/Users/runner/work/1/a/TestRelease/05-25_01.03.40/temp/BuildWithExternalJavaLibrary/BuildWithExternalJavaLibraryBinding/BuildWithExternalJavaLibraryBinding.csproj]

Commit ff7f467 removed the need to have a global .NET 7 preview install
to build and test Xamarin.Android.  This appears to expose an issue in
`AndroidDotnetToolTask`, which uses the latest `dotnet` in $PATH to run
some of our tools.  After upgrading some of these tools (class-parse,
generator) to net7.0, we are no longer able to run them as there is no
net7.0 runtime installed globally.

Improve the `AndroidDotnetToolTask` to better handle "sandboxed" .NET
installations by using a full path to `dotnet` if one is found.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 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