Search Unity

How to get intellisense setup for a custom embedded package?

Discussion in 'Package Manager' started by ZeroSinner, Apr 2, 2020.

  1. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
    I'm creating a custom embedded package, and my current methodology is to take the editor folder or any other folder that has C# code, drag it into my test project, make edits there, and then drag that folder back to the embedded package directory.

    My reason for doing this is if I edit a C# file in the embedded package it opens it in Visual Studio but treats it like a file outside of the currently loaded project (correctly so) and so does not give any intellisense at all.

    How can I generate an .sln or .csproj specifically for my packages so I have the typical setup needed for intellisense in VS or VS Code?
     
    Denis-535 and Egad_McDad like this.
  2. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
    Maybe it's not possible right now?

    If that is the case, a cool feature would be: whenever generating the typical .sln and .csprojs, creating a separate .sln and .csproj automatically for any embedded packages..

    Also it would be nice if there was a way to keep Unity from creating .meta files in embedded package folders.

    For now, I'm considering the following:
    - Copy existing .sln and .csprojs to my embedded package in a subdirectory `VS`.
    - Search and replace project GUIDs with newly generated GUIDs (with the exception of ProjectTypeGuids).
    - Mess around with the `<Compile ...` tags until it no longer looks for files in some Assets folder, but instead respects the folder structure I setup.
    - Script all this through node so I can easily update Unity (as I know the .csprojs make reference to version specific paths of Unity DLLs).

    Thoughts? Anybody foresee any issues with my direction?
     
  3. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    Hi @ZeroSinner,

    Normally Unity will generate a .sln for the whole project and .csproj for each asmdef plus the default assemblies (see the Predefined assemblies section in this Unity Manual page). Packages that are mutable (either embedded in the proejct, i.e. physically located under the project's Packages directory, or listed with a "file:" dependency in the manifest.json) should also have csproj generated for them.

    Which IDE are you using? What Unity version?

    By the way, if you need Unity to stop generating .meta files for assets, you need to hide those assets from the Asset Database (see the Hidden Assets section in this Unity manual page). Aside from that, it's not possible - meta files contain essential information for Unity to track the state and location of those assets, as well as maintain references between assets. Understandably they're not as critical for plain old C# code... but for asmdef assets, yes.
     
  4. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
    @maximeb_unity, thanks for such a thorough response!

    Based on your response I tried turning off Unity, deleting the .sln and .csproj files, and then running Unity again. But unless my C# code is in the Assets directory I still do not get any intellisense.

    I'm using 2019.3.7f1 (latest according to Unity Hub). and Visual Studio community 2019.

    As a further test I tried to use VS Code as well, but I still get no intellisense for files outside of the Assets folder. Is there something else I can do to help diagnose my issue?
     
  5. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    You might take a look at the Preferences > External Tools window, which controls the external IDE options. (I guess you already did since you said you tried both VS and VS Code integration.)

    Currently there is no Intellisense documentation available for code in packages added through dependencies (in manifest.json, or in packages's package.json). This is a known limitation. Instead, the compiled code is added to the generated .sln as "Assembly References" rather than as "Project References" on .csproj and source, so the IDE doesn't have any hint about the source.

    Only mutable packages (as mentioned above, either physically located under the project's Packages directory, or listed with a "file:" dependency in the manifest.json) should have a .csproj generated and therefore have Intellisense enabled. If that doesn't seem to be working, then something is definitely weird. So this would be the issue you're having, based on your initial post? Perhaps there's an update to VSTU (the Visual Studio Tools for Unity plugin in VS) or the com.unity.ide.vs package in Unity that would fix this.
     
    heu3becteh likes this.
  6. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
    The only com.unity.ide packages I see in the package manager are Rider Editor and VS Code... Is there something missing from my list? upload_2020-4-3_16-29-6.png

    This is a screenshot from my work computer which has VS2019 pro (not community) but I still have the same issue.
    upload_2020-4-3_16-30-25.png

    After taking this screenshot I clicked "Generate all .csproj files." That generated about 20 more .csproj files but intellisense still doesn't work.

    When I say that I mean that in a method block I type `Unity.` or `UnityEngine.` or `UnityEditor.` and I expect a list of valid and available types to show up afterwards, but I get nothing of the sort. Also the syntax highlighting is a little off, like it can't identify what's a class and what's a struct, etc.There are no red error squiggles even if I just make up a type out of thin air like `Game5Object`.

    upload_2020-4-3_16-36-35.png

    However if I pull the same .cs file into my Assets folder and double click on it, suddenly everything is working as I expect.

    Also I'm not sure how to check if the Unity VS extension has an update. Here is what I see:

    upload_2020-4-3_16-39-9.png

    EDIT:
    Oh and I forgot to include how my package is being included.
    In the packages folder I have a folder called "CubemapGenerator" and within that I have a "package.json" and a "Editor" folder which contains the .cs file I'm trying to edit.

    Packages\CubemapGenerator\Editor\CubemapEditor.cs
     
  7. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
    I'm embarrassed to say this, but I just realized that I can't get the Editor code to work from the packages folder.. It only works while it's been copied to the asset's editor folder....

    So maybe it's not even compiling. @maximeb_unity, you mentioned asmdef files. Maybe that's something I overlooked that still needs to be done?
     
  8. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
  9. ZeroSinner

    ZeroSinner

    Joined:
    Apr 12, 2013
    Posts:
    13
    @maximeb_unity, that's perfect. I just needed to add an asmdef in the Editor folder.

    Please consider this resolved.
     
    maximeb_unity likes this.
  10. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    Yes, code under Assets has some special predefined treatment based on file paths, but packages require asmdef assets to tell the compiler how to structure and compile the code.

    I'm glad you got it working - thanks letting us know!
     
  11. dkonikMS

    dkonikMS

    Joined:
    Jul 17, 2018
    Posts:
    2
    I just wanted to follow up as I hit this issue as well. I had to go to Edit->Preferences->External tools. Then check Generate .csproj for (you might not need all of these, I checked all of them though) "Embedded", "Local" and "Git" packages, and then click "Regenerate project files"
     
  12. RMGK

    RMGK

    Joined:
    Sep 30, 2011
    Posts:
    75
    Confirmed. Attached a screen shot to help. Use local packages.
    Screen Shot 2020-05-19 at 23.41.52.png
     
    Denis-535 likes this.
  13. JesperSmith

    JesperSmith

    Joined:
    Mar 23, 2018
    Posts:
    19
    I advise upgrading your Visual Studio Code Editor to 1.2.0. That solved a bunch of problems with intellisense for me.
     
  14. wlwl2

    wlwl2

    Joined:
    Jun 17, 2018
    Posts:
    29
    Should we always "Use local packages."? Are there any performance gains compared to embedded? I really don't think that I will reuse the code I have for other projects, and if I do, I can switch to Local later. The problem is that I have to set up repositories and version control for two codebases instead of one if I use Local.
     
  15. DrNeptune

    DrNeptune

    Joined:
    Sep 30, 2013
    Posts:
    3
    I'm experiencing the same thing. Only get intellisense when I move the package contents into the asset folder. None of the above suggestions helped me fix this.

    Any other ideas?
     
  16. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Hmm we really can't think of any other suggestions than what's already in the thread: update VSCode, get the latest com.unity.ide package, ensure you have an asmdef in the Editor folder in your package (https://docs.unity3d.com/Manual/cus-layout.html), in Preferences -> External Tools -> check the relevant package sources -> Regenerate project files.

    Possibly try these steps in a later Unity version and let us know if you still have issues
     
  17. NemoStein

    NemoStein

    Joined:
    Feb 17, 2014
    Posts:
    9
    I've followed each reply in this thread and can't figure a way to enable Intellisense in my local project as a "file:" dependency in manifest.

    My custom package (https://github.com/nemostein/locus) is local (not inside the Packages folder).
    I have a .asmdef and package.json for my package.
    My Unity project have my package in the manifest as :
    "sourbit.locus": "file:D:/Workspaces/sourbit/locus"
    If I generate a .csproj for my local packages, Unity creates a Sourbit.Locus.csproj with the wrong file paths in the files section:
    <Compile Include="Packages\sourbit.locus\...
    Because my package don't resides inside the Packages folder the whole project fails to compile.

    Not generating the additional .csproj files allows me to work with my Unity project fine, but there is no Intellisense in the package project.

    If I move my package code to the Projects/Sourbit.Locus/ folder (any other folder name fails) and generate the .csproj for embedded packages it works, but I'm REALLY against this, since my intention is to decouple my (reusable) package from (specific) Unity projects...

    VSCode 1.63.2
    VSCode C# extension (ms-dotnettools.csharp) 1.23.17

    Unity 2022.1.0b2
    com.unity.ide.vscode 1.2.4

    .NET SDK 6.0.101
    .NET Runtime 6.0.1
    Mono 6.12.0
    Code ($):
    1. ~ $ dotnet --info
    2. SDK do .NET (refletindo qualquer global.json):
    3.  Version:   6.0.101
    4.  Commit:    ef49f6213a
    5. Ambiente de runtime:
    6.  OS Name:     Windows
    7.  OS Version:  10.0.19044
    8.  OS Platform: Windows
    9.  RID:         win10-x64
    10.  Base Path:   C:\Users\nemos\scoop\apps\dotnet-sdk\current\sdk\6.0.101\
    11. Host (useful for support):
    12.   Version: 6.0.1
    13.   Commit:  3a25a7f1cc
    14. .NET SDKs installed:
    15.   6.0.101 [C:\Users\nemos\scoop\apps\dotnet-sdk\current\sdk]
    16. .NET runtimes installed:
    17.   Microsoft.AspNetCore.App 6.0.1 [C:\Users\nemos\scoop\apps\dotnet-sdk\current\shared\Microsoft.AspNetCore.App]
    18.   Microsoft.NETCore.App 6.0.1 [C:\Users\nemos\scoop\apps\dotnet-sdk\current\shared\Microsoft.NETCore.App]
    19.   Microsoft.WindowsDesktop.App 6.0.1 [C:\Users\nemos\scoop\apps\dotnet-sdk\current\shared\Microsoft.WindowsDesktop.App]
    20. To install additional .NET runtimes or SDKs:
    21.   https://aka.ms/dotnet-download
    22.  
    23. ~ $ mono --version
    24. Mono JIT compiler version 6.12.0 (Visual Studio built mono)
    25. Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    26.         TLS:           __thread
    27.         SIGSEGV:       normal
    28.         Notification:  Thread + polling
    29.         Architecture:  amd64
    30.         Disabled:      none
    31.         Misc:          softdebug
    32.         Interpreter:   yes
    33.         LLVM:          supported, not enabled.
    34.         Suspend:       preemptive
    35.         GC:            sgen (concurrent by default)
    36.  
    Tested VSCode "omnisharp.useGlobalMono" setting as "always", "auto" and "never"


    Current Workaround:
    I have a empty Unity project with all my custom packages embedded only to keep the Omnisharp happy and working, then I link the packages I want in my actual Unity project as a local package or git URL.

    It works, but this is counter-intuitive and is getting awkward as my list of packages increases because
    I can't open vscode with only one package at a time since it can't find the related .csproj
     
    misharigot and organick like this.
  18. misharigot

    misharigot

    Joined:
    Jul 6, 2021
    Posts:
    1
    I am using this workaround as well, but instead of using VS Code, I am using Visual Studio. It works, as you said, but I would also like to know if there is a better way.