Search Unity

Visual Studio Code Intellisense doesn't work with Unity 2018

Discussion in 'Scripting' started by CrowbarSka, Jul 30, 2018.

  1. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Hello!

    I have this problem only with Unity 2018.2.0f2.
    I'm working on other projects in Unity 2017.4.5f1 and the problem does not exist there.

    Whenever I open Visual Studio Code, Intellisense does not work at all, so the autocomplete doesn't work, and VS Code doesn't do stuff like automatically formatting code layout.

    Can anyone please help?

    I've tried:
    • Uninstalling & reinstalling VS Code.
    • Reinstalling VS Code plugins.
    • Checking/resetting Unity's script editor setting in Edit > Preferences > External Tools.

    EDIT! - the solution that worked for me is in this post.
    I simply had to install .NET Framework 4.7.1.
     
    Last edited: Sep 28, 2018
    DOUDOUNE444, mateomogar, PHL1 and 5 others like this.
  2. Daevin

    Daevin

    Joined:
    Jun 1, 2017
    Posts:
    11
    I'm having the same issue, and I'm getting this in the VSCode Output (seemingly related to the OmniSharp extension, but don't know if the fault lays in that or elsewhere):

    [fail]: OmniSharp.MSBuild.ProjectLoader
    The reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
    [warn]: OmniSharp.MSBuild.ProjectManager
    Failed to load project file 'f:\Projects\*******\Assembly-CSharp.csproj'.
    f:\Projects\*******\Assembly-CSharp.csproj
    C:\Users\#######\.vscode\extensions\ms-vscode.csharp-1.15.2\.omnisharp\1.30.1\msbuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1126,5): Error: The reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.


    Nothing has changed in my environment, save for updating Unity from 2018.1.X to 2018.2.1f1; I had Intellisense with 2018.1 in the morning, updated to 2018.2 over lunch, and no Intellisense in the afternoon.

    I've tried:
    • Uninstalling & reinstalling VS Code.
    • Reinstalling VS Code plugins.
    • Checking/resetting Unity's script editor setting in Edit > Preferences > External Tools.
    • Restarting PC
    Hope this gets addressed soon... although on the positive side of things, this has shown me that I rely too much on Intellisense!
     
    JamesArndt likes this.
  3. LBehring

    LBehring

    Joined:
    Mar 23, 2018
    Posts:
    1
    I'm having the same issue ... I tried the same solutions above but nothing seems to work. Waiting for a fix.
     
  4. jasilkm

    jasilkm

    Joined:
    Apr 26, 2017
    Posts:
    6
    Hey Anyone got a solution for this?
     
  5. FunkyBuddha

    FunkyBuddha

    Joined:
    Aug 17, 2017
    Posts:
    75
    Re-install visual basic 2017, it worked for me.
     
  6. fegabe

    fegabe

    Joined:
    Jan 3, 2015
    Posts:
    18
    I've fixed it changing to .NET 3.5 in my project (File -> Build Settings -> Player Settings). I had .NET 4.x before.

    Capture.PNG
     
  7. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    This seems to happen to me on and off... this is pretty annoying. I think I've got the exact same error message, but lately I've got a bit different I think.

    if I close a project that has only few classes, then open Unity, I get the similar error and autocomplete doesn't work in VS Code. If I restart unity, I get the same error. If I start a new project, I won't. The same thing repeats.

    This has happened at least with some 2018.x versions. I've got similar issues with OmniSharp and Atom, but I've since just used VS Code.

    Problem:
    Seems like VS code OmniSharp plugin tries to find some "stuff" related to msbuild - I have no idea what it is about. And seems like there are two copies of that folder, one in Visual Studio Community edition (that I installed along Unity) and one in VS Code folder.
    For some reason OmniSharp decides to load the one in Visual Studio folder, which results in something missing. This or similar issue has been reported in OmniSharp's github... but the solutions seem to be really esoteric, or I just missed the good ones.

    Hacky solution:
    Rename the Visual Studio msbuild folder to something else, like:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild ---> MSBuild.old

    Warning:
    This will most likely break the same feature in Visual Studio... but this is a fix for VS Code.


    If someone has a better solution, I'd be interested, but OmniSharp not working is a problem.
     
  8. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    Last edited: Sep 4, 2018
  9. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @DylanYasen

    If that was aimed at me, could you define what exactly I should download and install and so on?

    I think I've read that before, and also tried installing something like that, but it didn't help with this OmniSharp problem, but can't remember exactly...

    I'm on Windows 10.
     
  10. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    @eses I had this problem few weeks ago after I switched my project to use newer .net script runtime, and I fixed it by upgrading mono runtime to 5.14.
    I'm on mac tho, but try installing the latest mono from their official site.
    https://www.mono-project.com/download/stable/
     
    diazwatson likes this.
  11. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @DylanYasen

    Well now that I checked what I did, I had installed "mono-5.4.1.6-x64-0.msi" from that site as a fix... but it didn't help a thing.

    So maybe it's a bit earlier version.

    Do I have to just install this one, not anything special?
     
  12. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    I just tested it on my Windows machine. If you open your project with visual studio, it should notify you the missing .net framwork version
     

    Attached Files:

    • snip.PNG
      snip.PNG
      File size:
      12.6 KB
      Views:
      1,973
  13. santiagolopezpereyra

    santiagolopezpereyra

    Joined:
    Feb 21, 2018
    Posts:
    91
    By reinstalling VS Code plugins I suppose you mean actual VS Code plugins and not the VS Code plugin from the Asset Store.

    I had this problem twice. First time I fixed it by installing the Visual Studio Code asset from the Asset Store, which enables a full integration with Unity and VS Code. After installing it, remember going into Preference --> VS Code --> Enable Integration, and set Enable Integration to true.

    If this is not the problem, then I must ask: do you have a .project, project.json and your_project_name.sln files?

    I don't remember which one -sorry :) - but one of them was definitely needed for Unity intellisense and stuff. So just check which one you don't have and create it. I must add that you are not to create any of these files on your Assets folder, but on your project's folder. Your file tree should look something like this:


     

    Attached Files:

    RLink likes this.
  14. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @DylanYasen - Not working for me.

    I guess I have a bit different problem. I don't / didn't get error about anything missing. And it really seems to have something to do with VS Code just getting messed up between where to find MSBuild.

    Renaming folder seems to be the only fix I found... as soon as I rename the folder back, I get the error in VS Code.

    Also, Installing the latest mono didn't change this, just tested.
     
    Last edited: Sep 6, 2018
  15. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @santiagolopezpereyra

    I know the answer wasn't aimed at me - but I'm just curious...

    I don't think you need to use any 3rd party asset store project specific asset to have full integration any more?

    Also, what are .project and project.json files? I know very little about VS Code... I just use it, haven't had time to dig into it. I don't think we have such files - this is how newly created project looks like at least for me:

    https://www.dropbox.com/s/4jffxj479kfkn8f/20180906_VS_Code_project.PNG?dl=0
     
  16. santiagolopezpereyra

    santiagolopezpereyra

    Joined:
    Feb 21, 2018
    Posts:
    91
    Hi @eses

    Sorry for the delayed response.

    I believe the .project file is a file created by Visual Studio Code saving a project's data, such as dependencies and build specifications. The project.json file is a project management file usually created automatically on projects when using a editor -such as VS or VS Code-, though its creation can be deactivated on the settings. If you want to take a look at what it is specifically,

    https://docs.microsoft.com/en-us/nuget/archive/project-json

    take a look at that.

    This files are in deed necessary to my project for intellisense to work. If I erase them Intellisense ceases to work, and if I regenerate them it works again. Same happens with the VS Code package from the Asset Store.

    Anyhow, reading the post I made I clearly forgot to mention I work on Linux, so perhaps this requirements depend on the OS?
     
  17. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Hey everyone, a colleague helped me fix this. I too had the error listed above in the VS Code output log...

    .NETFramework,Version=v4.7.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version

    The solution was simply to a) read the error and b) follow its instructions XD

    How I fixed it...

    1. Close VS Code.
    2. Download and install Microsoft .NET Framework 4.7.1 here: https://www.microsoft.com/en-us/download/details.aspx?id=56119
    3. Restart VS Code.
    After that, Intellisense worked fine in a project that was formerly broken. This is in Unity 2018.2.7f1 on Windows 10.

    Hope that helps others with the same issue. Check the VS Code log when it warns you!
     
    Mctheodoren, samis3d, rprrs and 17 others like this.
  18. Daevin

    Daevin

    Joined:
    Jun 1, 2017
    Posts:
    11
    @CrowbarSka I did read the error and follow its instructions hahaha it didn't fix it then, and it didn't fix it now with 2018.2.10f2 either!

    For me, Intellisense still is not working.
     
  19. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Sorry to hear that, not sure what to suggest if you have installed .NET Framework 4.7.1 and it's still not working as that step solved it for me :/
     
  20. hychul

    hychul

    Joined:
    Jan 11, 2017
    Posts:
    1
    To fix the issue
    1. Download and install Microsoft's .NET Framework SDK any version with start 4.X from https://www.microsoft.com/net/download/visual-studio-sdks
    2. In VS Code, open 'Assembly_CSharp.csproj' file and change 'TargetFrameworkVersion' to what you installed .NET Framework SDK version
    3. And done! :)
     
  21. diegyoho

    diegyoho

    Joined:
    Oct 1, 2016
    Posts:
    1
    That's worked!
     
  22. ItsJayD

    ItsJayD

    Joined:
    Mar 20, 2015
    Posts:
    6
    I'm going to hop of this thread to voice a similar issue I've been having, but the issue isn't due to the fact I don't have the newest version, it's that Unity is defaulting the <TargetFrameworkVersion> value to 4.5, even when I try change it to 4.7.2. I've been trying to get a .net 4.5 SDK version, I've only found 4.5.2 so far, and that isn't fixing the lack of Intellisense. It's very frustrating, if anyone can suggest a fix I'd be very grateful
     
    atoickecaj and Alex_May like this.
  23. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    The lastest alpha somehow default to <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> and I installed Visual Studio (not code), updated .NET Core to latest, updated Mono to latest, and it still fails to start omnisharp in VSCode. I ended up search and replace with <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> and it works, but if Unity regenerate the project file I have to do it again. Also note that this is on macOS, so the obvious path of installing the framework or targeting pack does not work (it is .exe)
     
    atoickecaj likes this.
  24. n8burba

    n8burba

    Joined:
    Feb 4, 2013
    Posts:
    12
    On my laptop I had to install the latest .NET, restart and let Visual Studio Community 2017 create the sln and csproj files, then open VSCode. That solved the problem. HOWEVER, on my friend's laptop, with basically the exact same setup, Unity and Visual Studio would not update <TargetFrameworkVersion> in the *.csproj files (3 of them) from v4.5 to v4.7.1. So, we went in there and did it manually and VOILA it worked.
     
  25. pintu236

    pintu236

    Joined:
    Jan 13, 2019
    Posts:
    1
    For those who haven't solved this problem yet
    1. Open Assembly-CSharp.csproj file,it's in root of your project
    2. You only have to change this <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    3. Just replace with whatever version of .NET framework sdk installed.

    You should have both .NET framework and targeting sdk installed for a particular version,dont' use version less than 3.5
    cause it's now obsolete for unity 2018.

    This is a temporary solution cause targetFrameworkVersion always changes to unity default when you close the editor
     
    Last edited: Feb 7, 2019
    Z-DNA likes this.
  26. gdbjohnson3

    gdbjohnson3

    Joined:
    Mar 11, 2018
    Posts:
    13
    I'm working on Mac and this just started happening to me after I changed my Scripting Runtime Version... I moved my project from .Net35 Equivalient (Deprecated) to .Net4x, and I lose my Omnisharp. A bit annoying... the loss of this functionality is big enough to make me switch it back.

    Is there a better solution for mac users?
     
  27. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    latest unity on ubuntu

    could not get unity work at all
    installed all dependencies from thread
    worked

    could not find installable 4.7.1 like vscode asks for
    intalled mono
    works

    thanks

    Code (CSharp):
    1. <Project Sdk="Microsoft.NET.Sdk">
    2.     <PropertyGroup>
    3.         <TargetFramework>netstandard2.0</TargetFramework>
    4.     </PropertyGroup>
    5.     <ItemGroup>
    6.       <Content Include="Name.csv">
    7.         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    8.       </Content>
    9.       <Content Include="Syllable.csv">
    10.         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    11.       </Content>
    12.       <Content Include="Title.csv">
    13.         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    14.       </Content>
    15.     </ItemGroup>
    16. </Project>
    the new dotnet '1 line' project files are nice and easy to use but we stuck with 600 lines of should be git-ignored generated project files

     
  28. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,190
  29. skyLark9

    skyLark9

    Joined:
    May 2, 2018
    Posts:
    135
    I remember this happened to me last year. This was a headache and I couldn't find any solution.
    Now i'm using the free version of VS 2017 with Brackeys theme.
    Good luck guys.
     
  30. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  31. gdbjohnson3

    gdbjohnson3

    Joined:
    Mar 11, 2018
    Posts:
    13
    After some research, I found that upgrading mono is all that was needed to use the latest version of .net.
     
  32. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
  33. lajonss

    lajonss

    Joined:
    Mar 23, 2017
    Posts:
    1
    I recall fixing intellisense issues by deleting the ".vscode" directory inside the project I was working on.
     
    Chuk_iGek, XVI_LoLz and EvOne like this.
  34. spleen1334

    spleen1334

    Joined:
    Jul 22, 2017
    Posts:
    3
    Updating Mono fixed it for me.
     
  35. LoganBlack13

    LoganBlack13

    Joined:
    Apr 7, 2019
    Posts:
    2
    I confirm, works for me on Win 10 latest updates (so .net SDK latest ver. is included), with unity 2018.3.11f1 with VS code 1.33.1
     
    EvOne likes this.
  36. Daevin

    Daevin

    Joined:
    Jun 1, 2017
    Posts:
    11
    I ran into this issue again, running 2019.1.XX with Visual Studio Code on Windows 10.

    What fixed it for me was using the link provided by @hychul (which redirects to https://dotnet.microsoft.com/download/visual-studio-sdks for me) and installing the 4.5, 4.6, 4.7, 4.7.1, 4.7.2, and 4.8 SDKs under ".NET Framework", ensuring to download the items under "Developer Pack", NOT under "Runtime". Other links to .NET 4.7.1 seemed to have installed the Runtime pack, which definitely will not fix the issue.

    Was it overkill to install all 6 of the Developer Packs? Most likely... but that's what worked for me (though I didn't work backwards, I just did all 6 before testing again, so try working backwards down the list until it fixes it so you don't waste your time).

    And don't forget to set Visual Studio Code as your External Editor in the Unity Preferences instead of "... by extension".
     
  37. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    I recently did a fresh install of Windows 10 (upgraded from 7) and got it to work just using .NET 4.7.1, although not at first.

    This turned out to be the kicker for me. If you don't set that, Unity will default to "open by file extension", which just opens your scripts as regular individual script files when you double-click them in the Project tab, instead of opening the project. Once I changed the setting in Preferences > External Tools, it worked perfectly.
     
  38. ecv80

    ecv80

    Joined:
    Oct 1, 2017
    Posts:
    28
    For Ubuntu 18.04, in short: install mono from their official repos in their website (https://www.mono-project.com/download/stable/), not from Ubuntu repos!

    And that's it! I might just have saved you from several hours of vain research work and frustration. Here's how mine went:

    * search for error without actually reading it. Landed here. Read CrowbarSka's comment: "The solution was simply to a) read the error and b) follow its instructions XD". Laugh. Find out it isn't that straightforward for Linux. Cry.
    * I need a higher version of mono-reference-assemblies. I'll update everything. Failed, highest is still 4.0.
    * I found mono reference assemblies github! And they have v4.7.2! I'll download zip and install... Fail, building/installation instructions look more like library own developers instructions or package maintainer instructions. Look how other mono-reference-assemblies Ubuntu packages look. Wait... this is a bunch of .dll and I got them in this zip, so maybe I just have to install to the right place... hold it, hold it, hold it now... we're going overboard here and gonna leave things in an unusable state and we're working too much.
    * I read someone, somewhere, said those reference assemblies have to be same version than mono compiler... So maybe I should just try to update mono as a whole, are there backports? no... but hmm, I already checked latest unstable Ubuntu versions only have up to mono-reference-assemblies-4.0... so... Oh, I know! I'll check the official website and see.
    * Ok, I added the official repo and tried to update but it's saying it will install 4.0... hmmm.. Oh this guy on this bug tracker is saying he's having the same problem but when he actually went ahead and updated he got the 5.x version! Fair enough! I'll give a try! Yeah it installed 5.x!
    * Crossed fingers, let's give it a try by opening a project on the latest Unity beta. Woah! It works! What about an older project on 2017.3.x? It still works! Grrrrreeaaat!

    Which is why I hate having to put much time into setting up IDEs and stuff. It's always a freaking nightmare and specially a waste of time. Whenever I have to try a new engine, library, upgrade or whatnot I start shaking. Coding is not a problem but that thing really sucks. I was so happy to see that 2019 resolved the issue with sound delay on many not-top-brand phones including Xiaomi, and then when I resume working on vscode wah wah wah wah (
    )... that dreaded error (which I had seen before long ago BTW) and no intellisense... FML.
     
  39. MonkeyDW

    MonkeyDW

    Joined:
    Jun 2, 2019
    Posts:
    1
  40. Bambivalent

    Bambivalent

    Joined:
    Jan 25, 2017
    Posts:
    16
    Same here with Unity 2019.2.8 on win10. Don't bother with .NET 4.8, for me this was all I needed.
     
  41. xcb

    xcb

    Joined:
    Mar 5, 2015
    Posts:
    8
  42. FunkyBuddha

    FunkyBuddha

    Joined:
    Aug 17, 2017
    Posts:
    75
    I've gone thru so many solution, but what worked for me is to uninstall and reinstall it again.
    And voila, Intellisense started working again.
     
  43. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    198
    Absolutely broken on Mac whatever i do, on Unity 2018, 2019, and 2020. Tried switching project to .NET 3.5 (get same error but for version 3.5 instead of 4.7.1), tried installing latest Mono, .NET Core 3.1, restarting, rebuilding project files, everything. Days and days wasted. Contacted support days ago but no response. Disgusted doesn't even start to cover it.
     
  44. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    198
    I uninstalled every Unity and Visual Studio and Visual Studio Code, then reinstalled Unity + VS Community, and intellisense works in that. On Mac, I recommend doing this instead of trying to use VS Code.
     
  45. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    ActiveSim, alice_fusebox and jdtec like this.
  46. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @hawken

    Not true for everyone (luckily? We will see...) - although this has happened to me too, VS Code 1.42.0 works just fine with Unity - no problems so far with auto complete or debugging for example.
     
  47. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Just to clarify I think they now require a newer version of .net, which you may or may not have already installed. This was on Mac, I didn't have any problems on Windows10.
     
  48. HanSyuan

    HanSyuan

    Joined:
    Jul 7, 2014
    Posts:
    5
    @hawken Thanks! These reinstalls save me on mac.
     
  49. wild-Tom

    wild-Tom

    Joined:
    Sep 25, 2019
    Posts:
    1
    Hi,

    I had this error when opening the project with Visual Studio Code:
    .NETFramework,Version=v4.7.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version

    I had this configuration:

    Ubuntu 18.04
    Unity 2019.2
    Visual Studio Code

    This step by step instructions solved my problem.

    Additionally I needed to install a newer version of Mono, you can find
    here.
     
    Last edited: Mar 3, 2020
    ActiveSim likes this.
  50. ActiveSim

    ActiveSim

    Joined:
    May 10, 2019
    Posts:
    59
    Hi,

    after install Visual Studio Code, dotnet and mono (works very well thanks to your comments) I cannot connect over TCP or HTTP request anymore. Unity show this error in the console:
    Curl error 4: Unsupported proxy 'https://127.0.0.1:3128/', libcurl is built without the HTTPS-proxy support,
    and I get a request timeout due to the HTTP request.

    I'm working behind a proxy environment, but the error doesn't occur before the install.
    My configuration:
    - Ubuntu 18.04
    - Unity 2019.2

    I removed dotnet and mono again, but that doesn't change the problem.
    Has anybody the same problem or can help?