Skip to content

NativeAOT CLI: file-based app detection throws FileNotFoundException for 'Microsoft.Build' under AOT #54806

Description

@NikolaMilosavljevic

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions