Summary
The shared CLI parser path ParseResultExtensions.GetFileBasedAppEntryPointToken (added in #54653) calls VirtualProjectBuilder.IsValidEntryPointPath, which pulls in the Microsoft.Build assembly. Microsoft.Build cannot be linked into a NativeAOT image, so this method always throws System.IO.FileNotFoundException: Could not find file 'Microsoft.Build' when compiled with NativeAOT.
The NativeAOT CLI entry point (dn / NativeEntryPoint) calls GetFileBasedAppEntryPointToken to detect and defer dotnet app.cs file-based app invocations (see the remarks on the method), so this affects the real AOT CLI, not just the tests.
Evidence
The NativeAOT compiler (ILC) flags it at publish time:
ILC: Method '[dotnet-aot.Tests]Microsoft.DotNet.Cli.Extensions.ParseResultExtensions.GetFileBasedAppEntryPointToken(ParseResult)'
will always throw because: Failed to load assembly 'Microsoft.Build'
ILC: Method '[Microsoft.DotNet.Cli.Utils]Microsoft.DotNet.Cli.Utils.MSBuildForwardingAppWithoutLogging.ExecuteInProc(string[])'
will always throw because: Failed to load assembly 'Microsoft.Build'
At runtime the AOT binary then throws:
System.IO.FileNotFoundException : Could not find file 'Microsoft.Build'.
at Internal.Runtime.TypeLoaderExceptionHelper.CreateFileNotFoundException(ExceptionStringID, String)
at Microsoft.DotNet.Cli.Extensions.ParseResultExtensions.GetFileBasedAppEntryPointToken(ParseResult)
Affected tests (quarantined under AOT pending this fix)
These are skipped via the Skip parameter pointing at this issue in test/dotnet-aot.Tests/AotParserTests.cs:
AotParserTests.DetectFileBasedApp_WhenFirstArgIsCSharpFile
AotParserTests.DoesNotDetectFileBasedApp_ForBuiltInCommand
AotParserTests.DoesNotDetectFileBasedApp_ForNonExistentFile
Context
Surfaced by the NativeAOT CLI test CI hookup (#54719), which is the first time test/dotnet-aot.Tests runs under NativeAOT in CI. Once file-based app detection is made AOT-safe (so it no longer requires Microsoft.Build), the Skip annotations should be removed.
cc @baronfel
Summary
The shared CLI parser path
ParseResultExtensions.GetFileBasedAppEntryPointToken(added in #54653) callsVirtualProjectBuilder.IsValidEntryPointPath, which pulls in theMicrosoft.Buildassembly.Microsoft.Buildcannot be linked into a NativeAOT image, so this method always throwsSystem.IO.FileNotFoundException: Could not find file 'Microsoft.Build'when compiled with NativeAOT.The NativeAOT CLI entry point (
dn/NativeEntryPoint) callsGetFileBasedAppEntryPointTokento detect and deferdotnet app.csfile-based app invocations (see the remarks on the method), so this affects the real AOT CLI, not just the tests.Evidence
The NativeAOT compiler (ILC) flags it at publish time:
At runtime the AOT binary then throws:
Affected tests (quarantined under AOT pending this fix)
These are skipped via the
Skipparameter pointing at this issue intest/dotnet-aot.Tests/AotParserTests.cs:AotParserTests.DetectFileBasedApp_WhenFirstArgIsCSharpFileAotParserTests.DoesNotDetectFileBasedApp_ForBuiltInCommandAotParserTests.DoesNotDetectFileBasedApp_ForNonExistentFileContext
Surfaced by the NativeAOT CLI test CI hookup (#54719), which is the first time
test/dotnet-aot.Testsruns under NativeAOT in CI. Once file-based app detection is made AOT-safe (so it no longer requiresMicrosoft.Build), theSkipannotations should be removed.cc @baronfel