Hi, I upgraded my project from 2021.1 to the recently released 2021.2 and I’m getting build errors (IL2CPP), it seems Unity is unable to detect Visual Studio Build Tools:
Error Message
Internal build system error. BuildProgram exited with code -2146233088.
error: Could not set up a toolchain for Architecture x64. Make sure you have the right build tools installed for il2cpp builds. Details:
IL2CPP C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
Visual Studio 2019 or newer with C++ compilers and Windows 10 SDK (recommended)
Visual Studio 2017 with C++ compilers and Windows 10 SDK
Visual Studio 2015 with C++ compilers and Windows 10 SDK
Visual Studio 2017 (or newer) is detected using vswhere.exe as well as VSCOMNTOOLS environment variables.
Visual Studio 2015 is detected by looking at “SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir” in the registry as well as VSCOMNTOOLS environment variables.
Windows 10 SDK is detected by looking at “SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder” in the registry.
Unable to detect any compatible Visual Studio installation!
Unity.IL2CPP.Bee.BuildLogic.ToolchainNotFoundException: IL2CPP C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
Visual Studio 2019 or newer with C++ compilers and Windows 10 SDK (recommended)
Visual Studio 2017 with C++ compilers and Windows 10 SDK
Visual Studio 2015 with C++ compilers and Windows 10 SDK
Visual Studio 2017 (or newer) is detected using vswhere.exe as well as VSCOMNTOOLS environment variables.
Visual Studio 2015 is detected by looking at “SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir” in the registry as well as VSCOMNTOOLS environment variables.
Windows 10 SDK is detected by looking at “SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder” in the registry.
Unable to detect any compatible Visual Studio installation!
at Unity.IL2CPP.Bee.BuildLogic.WindowsDesktop.WindowsDesktopBuildLogic.UserAvailableToolchainFor(Architecture architecture, NPath toolChainPath, NPath sysRootPath)
at PlayerBuildProgramLibrary.PlayerBuildProgramBase.GetIl2CppToolChain(PlatformBuildLogic platform, Architecture architecture, NPath toolChainPath, NPath sysrootPath)
at PlayerBuildProgramLibrary.PlayerBuildProgramBase.SetupIl2CppBuild()
at PlayerBuildProgramLibrary.PlayerBuildProgramBase.SetupPlayerBuild()
at WinPlayerBuildProgram.WinPlayerBuildProgram.SetupPlayerBuild()
at PlayerBuildProgramLibrary.PlayerBuildProgramBase.RunBuildProgram()
at PlayerBuildProgramTypeWrapper.Run(String args)
at Program.Main(String args)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler ()
However, I’m able to build without any problems with Unity 2021.1 so it seems something changed in 2021.2. Here are the C++ Build Tools components I have installed:
And if I list all environment variables with “Get-ChildItem Env:” command in powershell I don’t see any VSCOMNTOOLS as suggested by the error message in Unity.
This is strange, despite the above outputs Unity 2021.1 is somehow able to locate my VS Build Tools 2019 installation since I can build fine there (install path perhaps?), but Unity 2021.2 doesn’t.
Edit:
Not sure if relevant, but “MSBuild.exe” is located under “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin>” in my computer.
Unity 2021.2 is using a new build path that should make iterative builds faster. But that also means it’s running different detection code for Visual Studio. I will need to dig into the old build path and see what it is in that path that detects Visual Studio installations that vswhere is not aware of.
Meanwhile to get you unblocked, try setting VS160COMNTOOLS environment variable to “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools”.
Awesome, I can confirm that setting VS160COMNTOOLS environment variable did the trick and I’m able to build now, thank you very much!
Additionally, I ran “vswhere” command with “-products ‘Microsoft.VisualStudio.Product.BuildTools’” option as suggested in the github link you shared and my Visual Studio instance is now listed.
Just to throw out, we ran into this issue as well. Creating the VS160COMNTOOLS environment variable solved this issue for us as well. We use the “Visual Studio Build Tools” installer for our build servers.
Same Issue here, setting environment variables didnt resolve.
Edit: I didn’t have desktop development with C++ installed via VS tools as I just relied on the unity hub for installing everything. I installed this and it now builds.
I can’t find a way to solve this issue. I’m using Unity 2021.2.14f and Visual Studio 2022 17.1.2.
What I tried:
Setting VS160COMNTOOLS user environment variable to C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools
Setting VS170COMNTOOLS user environment variable to C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools
Installing Desktop development with C++ module from Visual Studio Installer (I unchecked all the optional submodules, so I installed only the C++ core desktop features)