Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to tell Unity which version of Visual Studio to compile with?

Discussion in 'Scripting' started by icefallgames, Oct 15, 2020.

  1. icefallgames

    icefallgames

    Joined:
    Dec 6, 2014
    Posts:
    75
    It came with VS2019, which is what it wants to use. However, I need to use VS2017 in order to build with IL2CPP (because we use Rewired).

    Even though I have set VS2017 as my scripting tool (in Preferences, External Tools), it is still using VS2019 when compiling for IL2CPP. I can't find a setting anywhere for it. Is there one?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,522
    I'm not sure that's exposed... AFAIK Unity's compiler that it actually uses is internal, NOT what is in the IDE.

    Perhaps someone else can add more. There are other ways to include DLLs though, and other options to get stuff into the game.
     
  3. icefallgames

    icefallgames

    Joined:
    Dec 6, 2014
    Posts:
    75
    Interesting... I'm going off this post:
    https://forum.unity.com/threads/neverending-il2cpp-build.855235/#post-5703478

    That implies it is using some VS2019 functionality.

    The builds work fine on my home machine (which only has VS2017 installed), but fail on my work machine (which has both VS2017 and 2019 installed). Looks like the easiest thing for me to do will be to uninstall VS2019, then...
     
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    IL2CPP is separate from Unity. It is its own executable that Unity launches when you compile to IL2CPP. It automatically compiles with the latest version of Visual Studio that is installed. You can easily see this happening by opening the task manager during an IL2CPP compile and drill down to see the version of cl.exe that's actually doing the compile.

    You do not need to use Visual Studio 2017 because you use Rewired. The link you referenced gives you 3 options on how to make Visual Studio 2019 compile successfully by disabling the new optimizer and falling back to the older optimizer. By far, the easiest solution is option 3. All you do is stick a script in your project. Done.
     
    Last edited: Oct 15, 2020
    icefallgames and PraetorBlue like this.
  5. icefallgames

    icefallgames

    Joined:
    Dec 6, 2014
    Posts:
    75
    Ah cool, when I read that I misinterpreted it as disabling the optimizer altogether, which seemed to defeat the purpose.

    (Although I don't see much benefit with 2019 over 2017, so I might just uninstall it.)
     
  6. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    I'm assuming it will fall back to the old one. I can't prove that though. Information about the SSA Optimizer can be found here, including how to disable it:
    https://devblogs.microsoft.com/cppblog/new-code-optimizer/
     
  7. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,609
    Update: I just tested in VS 2019 16.7.6 (latest) and the problem still happens. This was the bug report when it was reported to Microsoft. They say to use this compiler flag to disable just the jump threading optimization:

    I've tested it and it works. So it looks like just disabling this part of the optimizer is enough to make it work. I'm going to change my script to use this method instead.