Search Unity

Question Visual Studio for Mac inserts unwanted "using" statements into my c# scripts

Discussion in 'Code Editors & IDEs' started by dynamicbutter, Aug 24, 2022.

  1. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    When using Visual Studio for Mac 17.4 preview build 715 with Unity 2021.3.8 I find that "using" statements are frequently being inserted into my c# scripts. I'm not sure the exact conditions that cause the insertions but the using statements are not needed and often break compilation.

    Does anyone have a solution for this problem? Other than the obvious... don't use this version of Visual Studio.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Which using statements? This only started to happen after you upgraded VS, and it worked correctly previously?
     
  3. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    One of them is using UnityEditor. There are several others that I can't remember atm. Yes, I just started noticing it since I upgraded VS.
     
  4. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    using System.Xml.Linq is another one
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,001
    I would not be surprised to hear that this happens with autocompletion.

    You might be typing the name of the class, you get a suggestions like "Classname" but there may be two or more classes of that name spread throughout namespaces and assemblies. But by the time you autocomplet the using statement was already added while you're reverting the autocompleted text to the actually desired class.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yep, does sound like a bug. Could you report it? https://unity3d.com/unity/qa/bug-reporting
     
  7. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    Thanks for the responses. If I figure out how to reproduce it, I will report a bug.
     
  8. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    using Mono.Cecil.Cil;
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Great, you reproduced it! How did you create this script? Please provide exact steps in the bug report.
     
  10. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    Pulled my unity project fresh from the VCS this morning and noticed this issue is gone. This process nuked all the cached files in the Library folder. I suspect this is the culprit, and in the future I will be doing a clean pull anytime I upgrade either Unity or Visual Studio.
     
  11. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    And you can confirm that you don't have the /Library folder under VCS, correct? That sounds like the case from your description but I just wanted to make sure.
     
  12. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    Ignore my last post in this thread. The problem has resurfaced. I think I was wrong about a correlation to the problem and cached Library files.
     
  13. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    Correct, /Library is in my .gitignore and not included in VCS
     
  14. teemukorh

    teemukorh

    Joined:
    Oct 28, 2014
    Posts:
    49
    I have had this same issue for few months as well. Driving me crazy and I have no idea how to go around it or how is it happening. I'm seeing a lot of UnityEditor* using statements, which is the breaking our cloud builds. Also using 2021.3.* LTS branch and visual studio 17.3.*
     
  15. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    63
    Switching to Visual Studio 2019 Community for Mac fixed the issue for me. Specifically v8.10.25 (build 2). FWIW I'm using Unity 2021.3.10.
     
    Last edited: Sep 21, 2022