Summary
dotnet test with MTP mode does not install the APK to the device before running instrumentation. This means users must manually run dotnet build -t:Install before dotnet test --no-build, which is a poor experience.
Background
dotnet run works correctly because it goes through the MSBuild Run target, which depends on Install:
<_RunDependsOn>
Install;
_Run;
</_RunDependsOn>
But dotnet test with MTP evaluates RunCommand/RunArguments and launches the process directly — it never triggers the Run target, so Install never runs.
Current Workaround
In #11130, the test explicitly calls dotnet build -t:Install before dotnet test. But end users shouldn't need to do this.
Proposed Fix
Ensure the APK is installed automatically when dotnet test is used. Some options:
- Hook into a
dotnet test target — add a target that runs before ComputeRunArguments or GetRunCommand that triggers Install when EnableMSTestRunner=true
- Have
Microsoft.Android.Run install the APK — when in dotnet-test mode, run adb install before am instrument
- Document the workaround — require
dotnet build -t:Install before dotnet test --no-build (least ideal)
Related
Summary
dotnet testwith MTP mode does not install the APK to the device before running instrumentation. This means users must manually rundotnet build -t:Installbeforedotnet test --no-build, which is a poor experience.Background
dotnet runworks correctly because it goes through the MSBuildRuntarget, which depends onInstall:But
dotnet testwith MTP evaluatesRunCommand/RunArgumentsand launches the process directly — it never triggers theRuntarget, soInstallnever runs.Current Workaround
In #11130, the test explicitly calls
dotnet build -t:Installbeforedotnet test. But end users shouldn't need to do this.Proposed Fix
Ensure the APK is installed automatically when
dotnet testis used. Some options:dotnet testtarget — add a target that runs beforeComputeRunArgumentsorGetRunCommandthat triggers Install whenEnableMSTestRunner=trueMicrosoft.Android.Runinstall the APK — when in dotnet-test mode, runadb installbefoream instrumentdotnet build -t:Installbeforedotnet test --no-build(least ideal)Related