Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Visual Studio not recognizing Unity Namespaces

Discussion in 'Editor & General Support' started by lifetree, Jan 23, 2019.

  1. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    Hi,

    I have this issue where after upgrading to Unity Plus and Unity Teams Advanced and Collaborate, my visual studio isn't working. When I open a script, all of the unity namespaces have red squiggly lines underneath (and all related functions and variable also have red lines underneath). Technically, everything still works, so unity is parsing it correctly, but VS won't recognize it. Makes it very difficult to write code. What would be the cause of this? I did change my unity user as well in case that might be an issue.

    I just downloaded a new copy of Unity with VS thinking that maybe something wasn't lining up, but nothing. Now, I didn't delete Unity or VS before downloading, thinking it would just overwrite both of them, but maybe it didn't overwrite VS. Should I download again after deleting both Unity and VS?

    Thanks for any help you can provide
     
  2. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    Update: I deleted Unity and VS, and redownloaded both from the Unity Download Assistant, to ensure that I have compatible versions. It is still doing it. Has anyone else had an issue like this?
     
  3. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    Update 2 (giving more information so you know what I have or haven't tried): Deleted .sln and .csproj files, and the entire Library folder to allow Unity to rebuild. Still getting the same issue. I am running out of ideas here. I really can't have this delay in my workflow. If anyone has any ideas, I would be eternally grateful.
     
  4. lucernagame

    lucernagame

    Joined:
    Nov 5, 2018
    Posts:
    19
  5. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    Thanks for your reply. I have all my scripts in the Assets/Scripts folder, so that second thread probably doesn't apply. Might just be a bug that has yet to be squashed. I have resorted to using a different script editor. I much prefer VS, but you gotta what you gotta do I guess.
     
  6. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    I found this error in VS, I'm guessing this is what is going wrong, but not sure how to fix. I manually obfuscated the path for security reasons and because it isn't relevant: Error MSB4019: The imported project "/Users/**********/obj/Assembly-CSharp.csproj.*.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. (MSB4019) (Assembly-CSharp).
     
  7. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    Ok, so I was able to fix this issue. Following is the solution in case it helps anyone:

    I realized that my associate named the new Unity project (because of Unity Teams Advanced and Collaboration) with a colon in it. So when VS went to make the solution file, it would name it based off of the folder name, but since it didn't like the colon, it would use a forward slash instead (big problem). I tried renaming it, but it would just keep recreating a solution using the forward slash because of the bad project name. So I renamed the project name to no longer have a colon, I deleted all .sln and .csproj files again, and I also deleted .vs directory (holds temp data and thought it might be interfering. It is automatically regenerated by VS, so no reason to not delete this). If you don't know how to delete .vs, go to your Terminal (Mac instructions), navigate to the project folder, and type "rm -R .vs". Simple as that.

    I had to find my project again as Unity didn't recognize the new name. Opened it up, opened a script in VS, and it worked!

    TL;DR, The name of the project folder had an incompatible character causing the .sln file to fail. Hope this helps someone!
     
  8. Saied_Azizia_Nuaim

    Saied_Azizia_Nuaim

    Joined:
    Dec 18, 2019
    Posts:
    1
    Thanks a lot lifetree that helped me
     
  9. nik_dris

    nik_dris

    Joined:
    Jun 6, 2020
    Posts:
    1
    So fond of your attitude in this post
     
  10. the_aia

    the_aia

    Joined:
    Feb 8, 2020
    Posts:
    7
    I was having this issue as well. It was fixed for me by removing and reinstalling Visual Studio Editor from the Package Manager.

    How to reinstall Video Studio Editor
    • The package manager can be accessed through Window > Package Manager
    • in the top left make sure you have "Packages: Unity Registry" selected
    • search in the top right for Visual Studio Editor.
    • Once you have that package selected it will say "remove" in the bottom right
    • after removing, you'll see a button in the bottom right to reinstall
    The most likely reason for this issue in my case was upgrading the project file to a new Unity version and then downgrading it
     
    Last edited: Sep 27, 2021
  11. Pablomon

    Pablomon

    Joined:
    Mar 9, 2015
    Posts:
    40
    After 6 hours trying everything, mgushanasjr solution worked for me!
     
    Autarkis and Opeth001 like this.
  12. paulobot_

    paulobot_

    Joined:
    Mar 8, 2020
    Posts:
    2
    reinstalling Visual Studio Editor from the Package Manager worked for me also, thank you
     
    samuelmorais likes this.
  13. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Fiordarancio likes this.
  14. Fiordarancio

    Fiordarancio

    Joined:
    Feb 5, 2018
    Posts:
    1
    The solution by lifetree worked in my case! I was having similar problems after moving the project folder (no renaming though): TMPro and Firebase namespaces not recognized by VS, still everything was working in Unity Editor. Thank you!
     
  15. krupps

    krupps

    Joined:
    Oct 17, 2017
    Posts:
    148
    I found the easiest solution for struggling with this. Go to the player settings, check all the libraries and update. Do a build in visual studio. Fixes all the issues, then go back and uncheck all but the first 2 and everything works again.
     
  16. brollsroyce

    brollsroyce

    Joined:
    Jun 7, 2021
    Posts:
    2
    IMPORTANT: Visual studio doesn't like Unity paths with symbols and spaces
     
    JJPena and Kurt-Dekker like this.
  17. dorashekhar1999

    dorashekhar1999

    Joined:
    May 2, 2020
    Posts:
    1
    In Unity Edit -> Preferences -> External Tools -> Select your external script editor
     
    dharashivkar777 likes this.
  18. samuelmorais

    samuelmorais

    Joined:
    Aug 3, 2012
    Posts:
    63
    I also reinstalled Visual Studio by the Package Manager and resolved the issue. Using Unity 2021.3.14f1 and VS Community 2019.
     
  19. Snedden27

    Snedden27

    Joined:
    Jul 4, 2020
    Posts:
    7
    reinstalling it from package manager solved it me as well. ty