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

PSA: If your VS Code C# extension stopped working...

Discussion in 'Code Editors & IDEs' started by Incode, Mar 5, 2020.

  1. mobilecat

    mobilecat

    Joined:
    Jul 24, 2017
    Posts:
    2
    I had a similar issue and just solved it for my case. Posting here in case it helps anyone.

    I noticed I had several solutions opening in Visual Studio Code each time I tried opening my active project. The C# extension setting defaults to null which picks the first solution alphabetically. I set mine to "MyProject.sln" force quit, re-opened and it's working now.

    This setting can be located by tapping on the Settings Cog button on the bottom right of the extension, select "Extension Settings" and then scroll down to "Omnisharp: Default Launch Solution" and set it to your .sln file. Close and re-open Code. Good luck!

    I'm running:
    MacOS 10.15.5
    Unity 2019.4.2f1
    C# 1.22.1
    Visual Studio Code 1.46.1
     
    PavelLangweil and alamaxsong like this.
  2. diggyk

    diggyk

    Joined:
    Aug 16, 2014
    Posts:
    24
    I still don't get a lot of code completion. I really hate this VS Code thing as the only good way to edit Unity scripts. Is there another tool that just works out of the box that understands Unity C#?
     
    R0man likes this.
  3. solidsuki

    solidsuki

    Joined:
    Mar 1, 2020
    Posts:
    3

    [warn]: OmniSharp.MSBuild.ProjectManager
    Failed to load project file 'c:\Users\Finn\Documents\Unity\CodeBreaker\Assembly-CSharp.csproj'.
    c:\Users\Finn\Documents\Unity\CodeBreaker\Assembly-CSharp.csproj
    c:\Users\Finn\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1178,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

    [fail]: OmniSharp.MSBuild.ProjectManager
    Attempted to update project that is not loaded: c:\Users\Finn\Documents\Unity\CodeBreaker\Assembly-CSharp.csproj

    I get this error everytime even though i have installed 3 different versions that developer pack. Please help!
     
  4. Aykutkaraca

    Aykutkaraca

    Joined:
    Jan 4, 2018
    Posts:
    33
    I get the same when an incompatible version of C# extension is installed in Visual Studio Code (if you use code). Click the gear button on C# extension and choose install another version. I use v.1.23.1.

    Or, you are missing mono:

    https://www.mono-project.com/download/vs/

    Then, on VSCode, go to settings-> "Omnisharp: Use global Mono" -> change it to always
     
    Last edited: Sep 10, 2020
  5. KokodokoGames

    KokodokoGames

    Joined:
    May 20, 2014
    Posts:
    40
    This issue just keeps reappearing. Intellisense works for a short while, and then suddenly it stops working because something has been updated in the background. It's so annoying, to the point where I would say VS Code is not a reliable tool for Unity programmers.

    I suggest Unity removes the option to use VS Code until they fix these serious issues.
     
    SrNull and v2-Ton-Studios like this.
  6. SrNull

    SrNull

    Joined:
    Jun 9, 2011
    Posts:
    25
    19 october and this VS Code issue is still happening
     
  7. Incode

    Incode

    Joined:
    Apr 5, 2015
    Posts:
    78
    This may be a new issue for people, I had to rollback my Omnisharp to 1.23.2 today.
     
    BHGAhuerta and ratking like this.
  8. timmccune

    timmccune

    Joined:
    Sep 27, 2018
    Posts:
    29
    Thank you. It is getting pretty annoying having to waste valuable time fixing this. I am glad I found your post before wasting another half a day yelling at my screen: "WHAT DO YOU MEAN THIS FIELD IS UNDEFINED! ITS RIGHT THERE!". UGH. It was actually showing me tooltips that were showing weird namespaces. IE: the script is in Project.Entities but it would show Project.Enditieries when i hover over it. So weird!
     
    Incode likes this.
  9. roguerotkosky

    roguerotkosky

    Joined:
    Nov 14, 2018
    Posts:
    1
    Saved the day! Thanks for the edits!
     
    Incode likes this.
  10. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,553
    Thanks for the information. I've discovered that VSCode is painting everything red, and that Visual Studio in last 15 years still hasn't managed to implement an option to disable automatic insertion of spaces in ){ .

    This workaround has saved me a lot of time.
     
  11. HypUIGuy

    HypUIGuy

    Joined:
    Feb 12, 2021
    Posts:
    1
    I didn't know what he meant, and his answer below was still unhelpful.

    THE VS CODE PACKAGE IS IN THE ASSET STORE Y'ALL.
     
  12. Danebulus

    Danebulus

    Joined:
    Jul 3, 2017
    Posts:
    5
    For Unity 2018, it seems that the last working "Debugger for Unity" version is 2.7.5
    Three months I have tried everything I could think of. No matter what I try, it doesn't work for me with the newer "Debugger for Unity 3.0.2".
     
  13. AlternativeShit

    AlternativeShit

    Joined:
    Feb 17, 2021
    Posts:
    18
    Can't make it work with any of the two versions... It doesn't detect my breakpoints.
     
  14. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    This may help some people.
    - Install VS19
    -- Install Unity file templates "created by: John Miler"

    --- Then close VS19 and reopen it.
    --- Now, open VScode and all errors will not be there.

    Thank you.
     
  15. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    I just used half a day to missing assembly references in VS Code. I'm using Windows, Unity 2020.1, VS Code 1.58.2.

    My success story:

    In Unity the relevant package is Visual Studio Code Editor (make sure it's this one). Update this to 1.2.3. Then, regenerate project files from Unity Preferences->External Tools.

    I also got a working result by downgrading the C# (Omnisharp) extension, but happy to get a working solution with the latest versions of everything.

    I found many confused comments here, and come to think of it, the Unity package name is somewhat confusing, it should be "VS Code Integration" or so. Another problem was that I have installed another package from Unity called VSCode, which again does something else to VSCode. Clear naming, please.
     
    Last edited: Aug 5, 2021
    niel-archer, ccw3 and jzwicker-sd like this.
  16. alamaxsong

    alamaxsong

    Joined:
    Sep 4, 2020
    Posts:
    2
    This works for me!
     
    mobilecat likes this.
  17. suryaelidanto

    suryaelidanto

    Joined:
    Oct 26, 2019
    Posts:
    1

    Thanks a lot, you've made my day
     
    Incode likes this.
  18. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    @mobilecat
    Insane, this is the first solution which works after 3 hours! Even though it sounds like a workaround, it points to the root cause.

    My other symptoms were Omnishap log completely empty(server not starting), in Unity 2019.4.30f. I made sure I had the correct .NET, regenerated the project files etc.
     
    mobilecat and akasurreal like this.
  19. clankill3r

    clankill3r

    Joined:
    Oct 19, 2017
    Posts:
    5
    I am so sick of the unity debugger breaking from time to time. It's one of the main reasons I would switch to unity. This S*** is happening for years now, and I don't think the situation will ever improve.
     
  20. Vivraan

    Vivraan

    Joined:
    Feb 2, 2018
    Posts:
    26
    Apologies for the necro but Unity Debugger Extension v3.0.2 is not working reliably with C# v1.23.15. What is the last recommended version in late 2021?
     
  21. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Like others have said, this is the ONLY thing that worked for me after hours of doing things such as installing dotnet runtimes, sdks, mono, and changing many other settings.

    I only have one .sln file in this directory, but I guess it wasn't loading it until I forced it to with this setting. The only issue I see here is that I will have to keep changing this for other projects now. I didn't used to need to do this on my prior mac, but this is a new one I am setting up. I am still grateful to have any solution at the moment, thanks!
     
    mobilecat likes this.
  22. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    I have a solution that is reproducible and has survived multiple upgrades over several months. No uninstalls or editing files or hacking mono settings.

    Check only the top 2 boxes and Regenerate project files. For me, this works every time on multiple projects and can be broken again by checking all the rest of the boxes. I tested it again just now after upgrading to 2020.3.24 and it worked again. After verifying it worked, I closed VS Code and "re-broke" it by checking the rest of the boxes. Closed VS Code again, checked only the top 2 boxes and it works again.

    Unity 2020.3.x (multiple versions)
    VS Code 1.6x (multiple versions)
    Visual Studio Code Editor asset 1.2.4 (latest as of Dec 2021)

    prefs.jpg
     
    JGameMaker92, PokerDawg and rstorm000 like this.
  23. rstorm000

    rstorm000

    Joined:
    Aug 19, 2010
    Posts:
    229
    THANK YOU
     
  24. JackPotato

    JackPotato

    Joined:
    Jul 16, 2018
    Posts:
    7
    The fact this is still an issue is upsetting. Nothing worked for me other than downgrading extensions. Very disappointing for fans of vs code.
     
    rsoares and marcospgp like this.
  25. btCharlie

    btCharlie

    Joined:
    Sep 19, 2019
    Posts:
    5
    On May 24th 2022, a new C# VS Code extension was released, the version 1.25.0. From this version onwards, the extension won't support mono-style development like Unity by default and
    omnisharp.useModernNet
    needs to be explicitly set to
    false
    in the extension settings, as per the official changelog.

    However, as of today, OmniSharp fails to load even with the settings turned off with a message
    Could not locate MSBuild instance to register with OmniSharp.
    and a timetout error for me. Reverting to the C# extension version 1.24.4 as per the original instructions from 2015 fixes this, however annoying that is.

    Hopefully it gets fixed soon.
     
  26. pillowfightio_conrad

    pillowfightio_conrad

    Joined:
    Mar 4, 2017
    Posts:
    10
  27. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
  28. tathagatadasgupta1234

    tathagatadasgupta1234

    Joined:
    Jul 24, 2022
    Posts:
    1
    c# is not working ....
    please help me out ......
    my project submission deadline is near...
    my vs code version
    Version: 1.70.0 (user setup)
    Commit: da76f93349a72022ca4670c1b84860304616aaa2
    Date: 2022-08-04T04:38:16.462Z
    Electron: 18.3.5
    Chromium: 100.0.4896.160
    Node.js: 16.13.2
    V8: 10.0.139.17-electron.0
    OS: Windows_NT x64 10.0.19044
     
  29. harryjc

    harryjc

    Joined:
    May 23, 2018
    Posts:
    1
    almost 3 years later, just want to say thank you! Crazy that this still isn't fixed. I reverted back to 1.21.12, and it solved my problems immediately.
     
  30. WaxyMcRivers

    WaxyMcRivers

    Joined:
    May 9, 2016
    Posts:
    59
  31. TripleQuotes

    TripleQuotes

    Joined:
    Aug 21, 2019
    Posts:
    1
    thank you so much.