Search Unity

VS CODE!! Does not work with asmdef files!

Discussion in 'Code Editors & IDEs' started by illinar, Nov 10, 2020.

  1. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    VS code doesn't see classes from my own assemblies outside the assembly of the given cs file. Assemblies are defined by asmdef files. Are there any settings that I missed or is there any fix for that?
     
    Last edited: Nov 11, 2020
    SunnyChow and Siccity like this.
  2. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    No compile errors by the way. Everything seems to be setup correctly, but VSCode doesn't work.
     
  3. Siccity

    Siccity

    Joined:
    Dec 7, 2013
    Posts:
    255
    I just had the same issue. I looked into my OmniSharp log in vscode and found that it complained about .NET Core SDK not being installed in my VS2019. So I opened up the VS installer and added that thing and after restarting VSCode it worked again. If that doesn't fix it alone, try also updating the VSCode package in unity to version 1.2.3
     
  4. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Thank you, this worked. It's also a brilliant idea to install all the .Net SDKs via the Visual Studio installer, I'm gonna always do it this way from now on, so handy.
     
    Siccity likes this.
  5. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Okay.. VS Code is completely falling apart again. It was loosing code autocompletion from time to time, now it's gone, and it shows a lot of errors that don't actually exist.

    It happened in a course of one evening and one session in Unity. Restarting VS code doesn't help, or restarting Unity. Hard tot tell what action exactly caused it. Because I'm used to it breaking all the time I didn't pay attention. But turned out it broke for good this time.

    I see no error messages from omnisharp.
     
  6. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Installing C# plugin version 1.23 fixed this (rolling back). This type of regression happens all the time with this plugin unfortunately. Maybe it's Unity's fault, in either case this thing breaks all the time.
     
    Last edited: Dec 7, 2020
    Siccity likes this.
  7. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    I have this problem again. Or maybe it's worse, I have no code completion at all with asmdef. 1.23.0 doesnt work either.

    Installed every Net SDK and targeting pack/
     
  8. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Solved it! The problem was about the project being renamed before asmdef files were created, and vs code was opening sln with the old name without asmdefs. Deleted the old sln and now it works.
     
    chelnok and mbaker like this.
  9. mbaker

    mbaker

    Joined:
    Jan 9, 2013
    Posts:
    52
    Thank you for documenting your struggles!
    I had the same issue and this helped me when I had run out of ideas :)

    Ultimately, what fixed my issue was going into the project(s) that reference the asmdef code and changing

    <ReferenceOutputAssembly>false</ReferenceOutputAssembly>

    to

    <ReferenceOutputAssembly>true</ReferenceOutputAssembly>


    It's a bit confusing since I don't believe VSCode has access to an assembly at this point (like it would in a normal .NET solution) but it does.

    For what it's worth, I'm on MacOS so Omnisharp is running off Mono instead of the .NET SDK.
     
  10. mbaker

    mbaker

    Joined:
    Jan 9, 2013
    Posts:
    52
    Ugh, not a permanent fix.
    Every time you change a file name in the asmdef it'll regenerate the .csproj file and reset the value...

    Looking around it seems I was just on some unlucky versions. Finding this post
    https://forum.unity.com/threads/cas...-is-set-to-false-in-project-reference.992883/

    I updated my Visual Studio Code Editor to v1.2.4 and all works as expected. The
    ProjectGenerator.cs
    class in the package no longer emits the
    <ReferenceOutputAssembly>
    at all.

    Looks like this was a combination of
    1. Omnisharp having a bug
    2. Then the Unity Package implemented a workaround
    3. Omnisharp fixed the bug and correctly evaluated the tag causing the Unity package's work around to now break evaluation.
    4. Unity package updated to no longer emit the work around.
     
    chelnok and illinar like this.