After upgrading from UE5.0.3 to UE5.1, we started seeing this error when trying to build Android Development from Visual Studio (VS2022 17.2.1):
Running UnrealBuildTool: dotnet "..\..\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" TestProject Android Development -Project="D:\unrealtest\TestProject\TestProject.uproject" -WaitMutex -FromMsBuild'dotnet' is not recognized as an internal or external command,operable program or batch file.
The relevant .NET SDK is installed and normally available by just 'dotnet' from a fresh Command Prompt, however, and this only happens when building from Visual Studio -- packaging for Android from the Unreal Editor works fine. We were able to reproduce this behavior in the vanilla 5.1.0 release and not on vanilla 5.0.3 to rule out our custom engine build and project setup.
The issue is that the Build.bat batch file invoked by the VS project is attempting to run plain 'dotnet' expecting it to be in the PATH, however the PATH environment variable is empty at that point in the batch file. This is in turn because UnrealBuildTool is generating the Android configuration in the .vcxproj file as Android_Development|Win64 instead of x64, but the VC++ build system in Visual Studio doesn't define an default ExecutablePath value for platform 'Win64', so it's blank. This is true both in the 5.0.3 and 5.1.0 generated projects. However, in 5.0.3 Build.bat runs GetDotnetPath.bat, which prepends the bundled .NET installation to PATH so the build works. In 5.1.0, Build.bat was changed to skip calling GetDotnetPath.bat for installed builds, and so it attempts to run dotnet.exe with the empty PATH from MSBuild and fails. The Editor directly runs the build without going through MSBuild and thus the PATH from the environment is preserved, which allows building Android from the Editor to succeed.
Note that we do not have the Android Game Development Extension installed, which appears to change the sln/vcxproj configuration generated by UBT. Many of our developers don't actually need to debug on Android from VS and are simply doing Android compile checks.
We found a couple of workarounds for this, one being to add a user.props file to the user profile to reinject a usable PATH, and another being to revert Build.bat to always running GetDotnetPath.bat even for installed builds. However, we'd like to know the correct way to solve this. Is there a redist install or build configuration option that should make this work, or is AGDE considered a required install for building Android from VS?