Search Unity

Unable to build IL2CPP in 2021.2

Discussion in 'Windows' started by samlletas, Oct 28, 2021.

  1. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    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:

    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.
     
    ed-fj, FlightOfOne and dpt2 like this.
  2. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    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"
     
  3. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    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.
     
    Last edited: Oct 28, 2021
  4. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    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".
     
    CrabSchell and samlletas like this.
  5. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    samlletas likes this.
  6. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    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.
     
    CrabSchell and bitter like this.
  7. CrabSchell

    CrabSchell

    Joined:
    May 27, 2014
    Posts:
    9
    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.
     
  8. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    I'm having this issue in unity 2021.2 using visual studio 2022 build tools, has there been any work done on this?
     
  9. bitter

    bitter

    Unity Technologies

    Joined:
    Jan 11, 2012
    Posts:
    530
    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.
     
    Whitebrim and SLGSimon like this.
  10. EyeDev44

    EyeDev44

    Joined:
    Apr 8, 2017
    Posts:
    149
  11. Cal_Mac

    Cal_Mac

    Joined:
    Feb 4, 2018
    Posts:
    22
    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.
     
    Last edited: Jan 25, 2022
  12. allyn_alves

    allyn_alves

    Joined:
    Jan 15, 2022
    Posts:
    18
    This was my issue as well, installed the C++ Desktop Environment in VS tools and now it builds
     
  13. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    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)
     
    xAdamQ likes this.
  14. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    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.
     
  15. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    I don't have any Visual Studio 2022 folder under Program Files (x86), the build tools are in the x64 in my case
     
  16. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    Solved: I had to install the MSVC module under Desktop development with C++ in Visual Studio Installer
     
  17. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    As a certified idiot... Can you please explain how I do this. I'm finding NOTHING with my Google fu
     
  18. samlletas

    samlletas

    Joined:
    Jan 2, 2016
    Posts:
    30
    In the visual studio installer app try selecting the same options as in the screenshot at the top of this thread.
     
    HuginnRaven likes this.
  19. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    upload_2022-4-18_1-54-1.png
    Am I blind or just still stupid?
     
  20. HuginnRaven

    HuginnRaven

    Joined:
    Dec 20, 2015
    Posts:
    33
    Ok... Never Mind! I fixed it finally!
    upload_2022-4-18_2-14-59.png
     
    Cyx_ likes this.
  21. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I just experienced this on Unity 2021.3.8f1 LTS, shouldn't this be handled by Unity or at least give us concise instructions on how to fix the error via the VS Installer? @bitter

    -edit-

    Ok, I see that clicking on one (an only this one) of the several lines of errors, I get more information on what exactly has to be installed on VS:
    Installing the win10 SDK from the Visual Studio installer fixed the compilation issues.
    Maybe this information could be stated more clearly as a notification window when you try to build for IL2CPP and it's missing something.
     
    Last edited: Jul 14, 2023
    matt_gb, Ignacii and Pookzob like this.
  22. Hanz-Hansal

    Hanz-Hansal

    Joined:
    May 6, 2015
    Posts:
    3
    I have similar issue trying Unity 2021.3.12f, Windows 11 on ARM and Visual Studio 2022.
    I know ARM isn't supported but both Unity and VS just works.
    Only building with IL2CPP causing troubles.
    I have installed Desktop development with C++ (including Windows 10 SDK) and Game development with Unity work flows.
    I have tried to set ENV VSCOMNTOOLS, VS160COMNTOOLS and VS170COMNTOOLS as C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools.

    I've checked regedit path SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder it exists.

    I was also tried VS2019 nothing helps, I'm still getting error:

    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 2022 or newer with C++ compilers and Windows 10 SDK (recommended)
    * Visual Studio 2019 with C++ compilers and Windows 10 SDK
    * 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!
    * Found Visual Studio 2022 installation without support for architecture x64


    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 2022 or newer with C++ compilers and Windows 10 SDK (recommended)
    * Visual Studio 2019 with C++ compilers and Windows 10 SDK
    * 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!
    * Found Visual Studio 2022 installation without support for architecture x64


    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)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)



    here is the output of vswhere

    Visual Studio Locator version 3.0.2+22c4136b72 [query version 3.3.2152.31801]
    Copyright (C) Microsoft Corporation. All rights reserved.

    instanceId: 6e89737a
    installDate: 11/2/2022 9:26:59 AM
    installationName: VisualStudio/17.3.6+32929.385
    installationPath: C:\Program Files\Microsoft Visual Studio\2022\Community
    installationVersion: 17.3.32929.385
    productId: Microsoft.VisualStudio.Product.Community
    productPath: C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe
    state: 4294967295
    isComplete: 1
    isLaunchable: 1
    isPrerelease: 0
    isRebootRequired: 0
    displayName: Visual Studio Community 2022
    description: Powerful IDE, free for students, open-source contributors, and individuals
    channelId: VisualStudio.17.Release
    channelUri: https://aka.ms/vs/17/release/channel
    enginePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service
    installedChannelId: VisualStudio.17.Release
    installedChannelUri: https://aka.ms/vs/17/release/channel
    releaseNotes: https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.3#17.3.6
    thirdPartyNotices: https://go.microsoft.com/fwlink/?LinkId=661288
    updateDate: 2022-11-02T16:26:59.7120693Z
    catalog_buildBranch: d17.3
    catalog_buildVersion: 17.3.32929.385
    catalog_id: VisualStudio/17.3.6+32929.385
    catalog_localBuild: build-lab
    catalog_manifestName: VisualStudio
    catalog_manifestType: installer
    catalog_productDisplayVersion: 17.3.6
    catalog_productLine: Dev17
    catalog_productLineVersion: 2022
    catalog_productMilestone: RTW
    catalog_productMilestoneIsPreRelease: False
    catalog_productName: Visual Studio
    catalog_productPatchVersion: 6
    catalog_productPreReleaseMilestoneSuffix: 1.0
    catalog_productSemanticVersion: 17.3.6+32929.385
    catalog_requiredEngineVersion: 3.3.2185.63263
    properties_campaignId: 2030:7760ad9e0a5e4d6aa0f4bb6d7a4242f2
    properties_channelManifestId: VisualStudio.17.Release/17.3.6+32929.385
    properties_nickname:
    properties_setupEngineFilePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe
     
  23. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    You should fill a bug report. I'm pretty sure no one expected it to run on ARM so maybe there is some magic string inside the compile process that must be changed for it to work.
     
  24. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Yup, please submit a bug report. We will fix it.
     
    atomicjoe likes this.
  25. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Same problem with
    Rider 2022.2.3
    Unity 2022.1.20f1
    Visual Studio 2022 with windows 10 sdk
     
  26. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Can you submit a bug report?
     
  27. MYUNGKEUN-OH

    MYUNGKEUN-OH

    Joined:
    Dec 7, 2016
    Posts:
    1
    I too have exactly the same problem. (Build fail for x64 on Windows11 arm)
    How can I submit a bug report?
     
  28. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  29. HernandoNJ

    HernandoNJ

    Joined:
    May 13, 2018
    Posts:
    75
    I had to install additional items from the VS installer including UWP - Universal Windows Platform - from the Unity Hub, and finally the build was done.

    upload_2023-1-2_15-54-11.png
     
    LjlCarrien and lightvirtual like this.
  30. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
  31. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Rider does not include C++ compiler so if you only have that installed, installing Windows SDK is not enough. However, another alternative is installing C++ build tools which take less disk space.

    However, Unity should be telling you what to install. If you come across any cases where Unity fails the build but doesn't tell you why, please report bugs on them. We've been trying really hard to reach a point where it points out exactly what you are missing and how to install it.
     
    Cyx_ and atomicjoe like this.
  32. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    78
    For Rider users:
    1. Download and launch Build Tools for Visual Studio from this page (scroll to the bottom, in the Visual Studio Tools section)
    2. Go to Single components
    3. Select only the latest MSVC C++ Build Tools (in my case it's "MSVC v143 - VS 2022 C++ Build Tools x64/x86")
    4. Install it and restart Unity
     
  33. Sanzui

    Sanzui

    Joined:
    Mar 12, 2019
    Posts:
    1
    Hi there, I get this trouble and fixed with import Windows11SDK.
    Unity ver 2021.3.3f1
    VisualStudio 2022
    everyone import VisualStudio2019, and Windows10SDK.
    But I solved at my version.
     
  34. umaradil

    umaradil

    Joined:
    Dec 11, 2018
    Posts:
    4
    thanks it worked
     
    samlletas likes this.