dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.65k stars 1.63k forks source link

[net9.0] Cannot build Maui.Controls.Sample.Sandbox project in the net9.0 branch locally #21687

Open brunck opened 1 month ago

brunck commented 1 month ago

Description

Trying to build the Maui.Controls.Sample project for iOS in VS 2022 Preview paired to a Mac using dotnet cake fails with: 10> Determining projects to restore... 10>/var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj : error NU1102: Unable to find package Microsoft.NET.ILLink.Tasks with version (>= 9.0.0-preview.3.24162.31) 10>/var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj : error NU1102: - Found 19 version(s) in nuget.org [ Nearest version: 9.0.0-preview.2.24128.5 ]

I first ran into the problem described in #21657 but I got past that by trying to launch the project using an available iOS simulator rather than just building the project.

Presumably using the cake script will build and use a local copy of dotnet that corresponds to what is needed to build the branch, which seems to be a version of preview 4 of .NET 9, although only preview 2 is available for direct download and installation at this time.

I was able to build the main branch and run the sample app on an iOS simulator using the stable version of VS 2022.

Edit:

Since .NET 9 preview 3, the error is similar, and it can be seen just by building the Maui.Controls.Sample.Sandbox project which is much simpler.

12>C:\Users\<username>\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\microsoft.net.illink.tasks\9.0.0-preview.3.24162.31\build\Microsoft.NET.ILLink.targets(301,5): error MSB4062: The "ComputeManagedAssemblies" task could not be loaded from the assembly C:\Users\<username>\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\microsoft.net.illink.tasks\9.0.0-preview.3.24162.31\build\..\tools\net472\ILLink.Tasks.dll. Could not load file or assembly 'file:///C:\Users\<username>\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\microsoft.net.illink.tasks\9.0.0-preview.3.24162.31\tools\net472\ILLink.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Steps to Reproduce

  1. Check out net9.0 branch locally
  2. Make sure VS 2022 Preview is installed
  3. Open a command prompt in the working folder and bootstrap/launch VS by using dotnet cake --target=VS
  4. After the cake script makes its way through the various tasks, VS 2022 Preview is opened with the solution
  5. Pair to Mac (using an Intel Mac; trying to pair to an ARM Mac results in pain and sadness) - this will install the needed workloads etc. on the Mac
  6. Build the Maui.Controls.Sample.Sandbox project

Expected - to successfully build the sample sandbox app

Actual - got the build error

Link to public reproduction project repository

use the net9.0 branch in this repository

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.3 GA

Affected platforms

iOS

Affected platform versions

any simulator - 17.0 or 17.2

Did you find any workaround?

No.

Relevant log output

New error:

12>C:\Users\<username>\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\microsoft.net.illink.tasks\9.0.0-preview.3.24162.31\build\Microsoft.NET.ILLink.targets(301,5): error MSB4062: The "ComputeManagedAssemblies" task could not be loaded from the assembly C:\Users\<username>\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\microsoft.net.illink.tasks\9.0.0-preview.3.24162.31\build\..\tools\net472\ILLink.Tasks.dll. Could not load file or assembly 'file:///C:\Users\<username>\AppData\Local\Temp\Microsoft.Maui.Cache\NuGet\packages\microsoft.net.illink.tasks\9.0.0-preview.3.24162.31\tools\net472\ILLink.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Old error:

10>Maui.Controls.Sample -> C:\s\maui\src\Controls\samples\Controls.Sample\bin\Debug\net9.0-ios\iossimulator-x64\Maui.Controls.Sample.dll
10>Tool /Users/<username>/Library/Caches/Xamarin/XMA/SDKs/dotnet/dotnet execution finished (exit code = 1).
10>  Determining projects to restore...
10>/var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj : error NU1102: Unable to find package Microsoft.NET.ILLink.Tasks with version (>= 9.0.0-preview.3.24162.31)
10>/var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj : error NU1102:   - Found 19 version(s) in nuget.org [ Nearest version: 9.0.0-preview.2.24128.5 ]
10>  Failed to restore /var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj (in 576 ms).
10>C:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9436-net9-p4\targets\Xamarin.Shared.Sdk.targets(1179,3): error : /Users/<username>/Library/Caches/Xamarin/XMA/SDKs/dotnet/dotnet exited with code 1:
10>C:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9436-net9-p4\targets\Xamarin.Shared.Sdk.targets(1179,3): error : Determining projects to restore...
10>C:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9436-net9-p4\targets\Xamarin.Shared.Sdk.targets(1179,3): error : /var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj : error NU1102: Unable to find package Microsoft.NET.ILLink.Tasks with version (>= 9.0.0-preview.3.24162.31)
10>C:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9436-net9-p4\targets\Xamarin.Shared.Sdk.targets(1179,3): error : /var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj : error NU1102:   - Found 19 version(s) in nuget.org [ Nearest version: 9.0.0-preview.2.24128.5 ]
10>C:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9436-net9-p4\targets\Xamarin.Shared.Sdk.targets(1179,3): error :   Failed to restore /var/folders/m1/j6flwm0d4kbcxqkgkyq74n8m0000gp/T/tmp630e8267.tmp/ComputeAotCompilerPath.csproj (in 576 ms).
10>Done building project "Maui.Controls.Sample.csproj" -- FAILED.
jfversluis commented 1 week ago

While this obviously also should work for the Pair to Mac scenario, have you tried to do this directly on a Mac?

Does that work?

brunck commented 1 week ago

Haven't gotten that to work yet, but since I'm blocked in this direction, it's time to turn back to Mac.

brunck commented 1 week ago

@jfversluis Trying to configure VS Code on a Mac to build or run anything .NET MAUI is incredibly painful , and I can't get the configuration to work. Xcode is installed properly, and VS Code insists that Xcode is not installed.

I was able to get iOS to build using git clean -xdf dotnet cake --ios

and then run on a simulator using the .NET MAUI extension to set the startup project and debug target, and via F5 to commence running the app.

The latest VS Windows errors are on this VS feedback issue that you closed as a duplicate.

jfversluis commented 1 week ago

Have you seen the instructions here? Do those work for you?

I think in regard to the original error we might be in a bit of a weird state were something got inserted into builds or manifests (Microsoft.NET.ILLink.Tasks) which isn't available on public NuGet feeds yet and that is why you are seeing that and are currently blocked. They should be available when a new preview comes out.

brunck commented 1 week ago

@jfversluis The errors are quite a bit different now. You can see screen recordings and logs in the VS community issue you closed as a duplicate. They are the same with preview 7 of VS 2022 preview as they were with preview 6.

Here are examples of these errors:

`6>c:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9540-net9-p5\tools\msbuild\iOS\Xamarin.Shared.targets(1428,3): error MSB4018: The "FindItemWithLogicalName" task failed unexpectedly. 6>c:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9540-net9-p5\tools\msbuild\iOS\Xamarin.Shared.targets(1428,3): error MSB4018: System.MissingMethodException: Method not found: 'System.String Xamarin.Localization.MSBuild.MSBStrings.get_M0149b()'. 6>c:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9540-net9-p5\tools\msbuild\iOS\Xamarin.Shared.targets(1428,3): error MSB4018: at Xamarin.MacDev.Tasks.FindItemWithLogicalName.Execute() 6>c:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9540-net9-p5\tools\msbuild\iOS\Xamarin.Shared.targets(1428,3): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 6>c:\s\maui\bin\dotnet\packs\Microsoft.iOS.Sdk.net9.0_17.2\17.2.9540-net9-p5\tools\msbuild\iOS\Xamarin.Shared.targets(1428,3): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() 6>Done building project "Controls.Core.csproj" -- FAILED.` `6>c:\s\maui\src\Controls\src\Core\Visuals\VisualTypeConverter.cs(32,5,32,32): error IL2026: Using member 'Microsoft.Maui.Controls.VisualTypeConverter.ScanAllAssemblies(Dictionary)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The IVisual types might be removed by trimming and automatic registration via assembly scanning may not work as expected. 6>c:\s\maui\src\Controls\src\Core\TypeConversionHelper.cs(40,9,40,83): error IL2026: Using member 'Microsoft.Maui.Controls.TypeConversionHelper.TryConvertUsingImplicitCastOperator(Object, Type, out Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The method uses reflection to find implicit conversion operators. It is not possible to guarantee that trimming does not remove some of the implicit operators. Consider adding a custom TypeConverter that can perform the conversion instead. 6>c:\s\maui\src\Controls\src\Core\BindablePropertyConverter.cs(104,16,104,40): error IL2026: Using member 'GetControlType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Loading XAML at runtime might require types and members that cannot be statically analyzed. Make sure all of the required types and members are preserved. 6>c:\s\maui\src\Controls\src\Core\BindablePropertyConverter.cs(105,11,105,44): error IL2026: Using member 'Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(Type, String, IXmlLineInfo)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Loading XAML at runtime might require types and members that cannot be statically analyzed. Make sure all of the required types and members are preserved. 6>c:\s\maui\src\Controls\src\Core\BindablePropertyConverter.cs(68,12,68,49): error IL2026: Using member 'Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(Type, String, IXmlLineInfo)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Loading XAML at runtime might require types and members that cannot be statically analyzed. Make sure all of the required types and members are preserved. 6>c:\s\maui\src\Controls\src\Core\BindablePropertyConverter.cs(77,12,77,49): error IL2026: Using member 'Microsoft.Maui.Controls.BindablePropertyConverter.ConvertFrom(Type, String, IXmlLineInfo)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Loading XAML at runtime might require types and members that cannot be statically analyzed. Make sure all of the required types and members are preserved. 6>c:\s\maui\src\Controls\src\Core\Compatibility\Handlers\Shell\iOS\ShellSearchResultsRenderer.cs(45,8,45,84): error IL2026: Using member 'Microsoft.Maui.Controls.BindableObjectExtensions.SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using bindings with string paths is not trim safe. Use expression-based binding instead. 6>c:\s\maui\src\Controls\src\Core\Shell\ShellContent.cs(331,27,331,63): error IL2072: 'name' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperty(Type, String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. 6>c:\s\maui\src\Controls\src\Core\Shell\ShellContent.cs(351,27,351,63): error IL2072: 'name' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperty(Type, String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. 6>Done building project "Controls.Core.csproj" -- FAILED.`

As far as the instructions you mentioned, I have no issues with those. I am having trouble installing Android SDKs and getting them to be in the location that matches the environment variables to put into the .zprofile, but that is kind of out of scope and I was able to work around that as mentioned in my previous comment.