Unable to build IL2CPP in 2021.2

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:

I don’t really want to install the full Visual Studio Editor just to be able to build in Unity, any ideas of what could be wrong?

Thanks in advance.

3 Likes

Hi Sam! Do you mind posting the output of vswhere.exe on your computer?

Mine is located at “C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe”

Hi bitter! Sure, here is the output:

Using “-format xml” option returns:

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.

Thank you!

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”.

3 Likes

I found the issue - vswhere -all does not find the installation of BuildTools · Issue #22 · microsoft/vswhere · GitHub

Let me know if the workaround using VS160COMNTOOLS worked for you. Meanwhile I’ll put in a patch supporting BuildTools.

1 Like

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.

2 Likes

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.

I’m having this issue in unity 2021.2 using visual studio 2022 build tools, has there been any work done on this?

Patch has been submitted but has not yet made it into 21.2 yet. Sorry, I should have done a better job at pushing this forward.

2 Likes

Same

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.

4 Likes

This was my issue as well, installed the C++ Desktop Environment in VS tools and now it builds

4 Likes

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)
2 Likes

Try setting VS170COMNTOOLS to C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools

Even thought Visual Studio 2022 is now 64 bit the build tools seem to be installed in the x86 program files folder.

I don’t have any Visual Studio 2022 folder under Program Files (x86), the build tools are in the x64 in my case

Solved: I had to install the MSVC module under Desktop development with C++ in Visual Studio Installer

10 Likes

As a certified idiot… Can you please explain how I do this. I’m finding NOTHING with my Google fu

In the visual studio installer app try selecting the same options as in the screenshot at the top of this thread.

1 Like


Am I blind or just still stupid?

Ok… Never Mind! I fixed it finally!

1 Like