Search Unity

2021 Scripting Define Symbol changes not reflected in Visual Studio 2019

Discussion in 'Editor & General Support' started by ScottAdams, Oct 20, 2021.

  1. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    Change project from Unity 2019 to 2021.1.25f1 All is working fine except the following.

    It used be changing the Scripting Define Symbols in "Project Settings/Player/Other" would instantly cause Visual Studio 2019 to recompile per the new Symbols set.

    Now it doesn't in 2021. Is there a setting I am missing? Is this a bug?
     
  2. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    I had some compile errors I hadn't noticed That seems to have fixed the issue.
     
  3. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    Nope it still sometimes won't update VS. I have to exit VS and restart
     
  4. Kolichikov

    Kolichikov

    Joined:
    Jul 21, 2014
    Posts:
    16
    This also does not work for me (Version 2021.1.5f1). Unity seems to recompile, and I see errors from the code being excluded based on the define symbols, but Visual studio doesn't get updated (even when restarted).

    I can see that after clicking Apply in Player Settings, the csproj files are not updated. However, when I remove a symbol that didn't function from the Player Settings, suddenly it IS added to the csproj files <DefineConstants> tag. Adding the symbol back to PlayerSettings again removes it from the csproj files. This seems backwards to me (I have to add and then remove a symbol from PlayerSettings for it to show up). Side effect: There's no way to actually remove the symbol, because adding it back will sometimes cause VS to stop finding the System namespace.
     
  5. ycode

    ycode

    Joined:
    May 1, 2016
    Posts:
    4
    As of 2021.3.1f1, what I can see with Project Settings view - Scripting Define Symbols section on Unity Editor is that every time clicking on the Apply button under the input field, the second last edit is reflected on the <DefineConstants> in csproj files.

    However, the modification is not saved to `/ProjectSettings/ProjectSettings.asset` file by the Apply button. By the way, csproj files are (re)generated based on this file. The operations that save the change to the `ProjectSettings.asset` file are [File - Save Project] from the Unity Editor menu, or restarting Unity Editor.

    All in all, there're two ways to make sure the symbol updates are certainly reflected on `ProjectSettings.asset` file and all the csproj files.

    1. Close Unity Editor (changes are saved to ProjectSettings.asset)
    2. Open Unity Editor (csproj files are regenerated)

    Or,

    1. [File - Save Project] or [File - Save Project] from the Unity Editor menu (changes are saved to ProjectSettings.asset)
    2. Press + button under Project Settings view - Scripting Define Symbols section on Unity Editor, and leave it empty
    3. Click the Apply button (csproj files are regenerated)

    These are confirmed on macOS 12.3.1
     
  6. baobieber

    baobieber

    Joined:
    Apr 19, 2016
    Posts:
    3
    I found a simple solution, i hope it can help u!
    1.Quit Visual Studio
    2.Unity -> Preferences -> External Tools -> Regenerate project files
    3.Reopen Visual Studio
     
    xinatcg and wlad_s like this.
  7. TeKGameR

    TeKGameR

    Joined:
    Aug 9, 2015
    Posts:
    37
    Hi, this thread is a bit old but i've spent hours finding the solution to instantly update the scripting define symbols inside VS2022...

    I've first discovered adding an empty scripting symbol and clicking apply was working.
    Then i saw that Regenerate project files works like a charm.

    So after some lookup in dnSpy to find the method.

    You simply have to call
    Code (CSharp):
    1. CodeEditor.Editor.CurrentCodeEditor.SyncAll();
    into an editor script when you want to update the vs project so it get the new defines.

    Works perfectly for me.