Description
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?
Yes, we're seeing this issue with the stock UE5.1 installed from the Epic launcher, and it is taking the goto. Swapping the order of those two sections so that GetDotnetPath.bat always runs does the fix the issue.

We do have dotnet.exe in PATH, but the issue is that MSBuild is not passing it through when UBT is invoked via the NMAKE project in Visual Studio. Echoing %PATH% before the GetDotnetPath.bat call gives blank output. It's running the NMAKE command line with an empty path instead of the system environment PATH because it doesn't have ExecutablePath configured for the Win64 platform that the project/solution setup is using. For the x64 platform, that defaults to $(VC_ExecutablePath_x64);$(CommonExecutablePath), which does include PATH. But as far as I can tell, the Generate Project Files output is not configured to build Android with 'x64' as the project platform, it's set up to use 'Win64'.

I have fixed the batch file for 5.2 but the PATH variable not being passed through is still a bug with the VS project generation as far as I can tell. 

Steps to Reproduce

n/a

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-175094 in the post.

0
Login to Vote

Fixed
ComponentUE - Foundation - Cpp Tools - UnrealBuildTool
Affects Versions5.1
Target Fix5.3
Fix Commit23843024
CreatedJan 25, 2023
ResolvedApr 25, 2023
UpdatedAug 14, 2023
View Jira Issue