Search Unity

Searching code in Package Manager from Visual Studio

Discussion in 'Package Manager' started by DougRichardson, Aug 17, 2018.

  1. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    I've been experimenting with the Package Manager, specifically with the PostProcessing package.

    Previously, my generated Visual Studio projects contained source code for PostProcessing (since it was in my Assets folder). This allowed me to use the Visual Studio text search tools to find code in PostProcessing another packages I'd installed in my Assets folder.

    However, using PostProcessing from Package Manager, I noticed that Visual Studio text search tools no longer work. It appears that Unity Package Manager packages do not appear in the Visual Studio project at all anymore.

    Is there anyway to include the packages in my project like before? If not, is there another project that I can open to at least search each package individually?
     
    tonytopper likes this.
  2. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
  3. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    I have VSTU 3.8.0.3 installed.

    If I press F12 on a symbol, I jump to the definition in a Temp folder. For example, if I F12 on PostProcessVolume in my code, it jumps to:

    C:\Users\doug\AppData\Local\Temp\MetadataAsSource\6b16eb2592df43308294c28d5ea28df4\9769368ebf3543a885e48baa2f6220a7\PostProcessVolume.cs

    At that point, if I do a Find All on "PostProcessVolume" it will appear in the search results. However, other post processing file results do not appear, only the ones I've done an F12 lookup on.
     
  4. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Hi,

    Adding @lukaszunity to the thread.

    Previously VSTU was in charge of generating project files and solution file. Starting with 2018.1, VSTU is now using Unity's generated files. So probably the different generation logic introduced this behavior.

    Could you try to provide a working project (like when using an older Unity version < 2018.1), and your current project so that @lukaszunity will be able to diff generated files and find the potential issue ?

    Thanks!
    Sebastien Lebreton [MSFT]
     
  5. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    Hi Sebastien. The difference isn't between older versions of Unity and newer versions of Unity. The difference is between using the new package system and not using the new package system.

    Previously, you brought packages into your Assets folder, which meant they were included in the Visual Studio project.

    Now with the Package Manager, when you import a package it's source files are no longer included directly in the Visual Studio project (so the Find in Files tool doesn't work for files in the package).

    I don't think this is a Visual Studio bug, I think it's just due to how the Package Manager works.

    The reason I started this thread is because, while I like the new Package Manager, it does make understanding your games code base more difficult since it's harder to search all files in your game from a single place.
     
    Tonio1308 and tgrotte like this.
  6. LaurensMMonk

    LaurensMMonk

    Joined:
    Jun 6, 2018
    Posts:
    6
    While trying to understand the lightweight render pipeline I encountered this same problem; Visual Studio doesn't know where definitions are because the packages aren't in the same solution.

    My work-around was to clone the scriptable render pipeline code from github (though I suppose you could also grab the packages from the cache) and add it to a Packages subfolder under assets. This can result in conflicts with the version compiled via package manager, which I haven't figured out how to solve yet, so the work-around only really works in clean Unity projects. You might then still run into issues with shader includes, so you might have to change those to relative paths.

    Once I worked through all those error messages, I managed to get the lightweight scriptable pipeline working this way. Maybe you can do the same for the post processing package.



    That said, it seems to me that Unity should add the packages to the same solution file, so that Visual Studio's functionality just works. (Before trying this work around, I made sure that I was using the latest Unity plugin for Visual Studio 2017, using Microsoft's updater.)
     
  7. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    I would like to bring this up again @okcompute_unity as this is super annoying.
    • Packages in the project don't show up in Visual Studio project
    • after double-clicking on a file in a package Visual Studio can't find any references in it (due to nothing being loaded)
    • compare this to the behaviour in Rider, where packages can be navigated "as usual"
     
  8. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    @fherbst , do you have the latest version of VSTU installed?
     
  9. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    How do I find out what the latest is?
    Visual Studio tells me: "Visual Studio 2017 Tools for Unity", version 3.9.0.3
    Unity Package Manager tells me: "Visual Studio Editor", version 1.0.11
    Unity version is 2019.3.0b1, but I've seen this since package manager got introduced

    The behaviours I'm seeing:
    • Visual Studio opens many many instances - sometimes after double clicking on a newly created script, sometimes if some scripts were already open in VS (from the same project but inside different asmdef)
    • in some projects I'm getting csproj files for Packages in some not (on the same Unity version), this seems to depend on whether the project was updated or newly created (works better in newly created ones)
    • in some projects I had to manually delete sln+csproj files that existed before new ones were generated for different packages (in one case I had a sln file that Unity created back in 4.7, in a project that I continuously updated, and that sln file seemed to have prevented generation of package csproj files)
    • I can't navigate code inside of packages when opening them in visual studio, also I can see that there is no csproj for them
    • the magical button "open C# project" only creates csproj files for things in Assets and for packages that are editable, but not for regular packages
     
  10. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
  11. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    It says "Added support for Unity packages in the UPE. Only Referenced packages (using manifest.json in the Packages folder) and Local packages (embedded in the Packages folder) are visible." Version 4.1.0.0, released May 21, 2019.

    However, the latest available version according to the Extensions marketplace is 3.9.0.3. Visual Studio 2017 has all the latest updates, the machine has all the latest Windows updates. Are you seeing a different version?

    upload_2019-9-9_23-39-55.png
     
  12. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    I'm not seeing anything. I'm not using Visual Studio and VSTU! :p
     
  13. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    How helpful!

    (seriously...?!)
     
    Tonio1308, waltran, Leniaal and 2 others like this.
  14. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    Yes, I'm serious. I don't use VSTU. I'm sorry I cannot be of help here. This is the community forum, so maybe a user or one the VS plugin authors/maintainers can respond (One of them is on this thread). You can also fill a bug to Microsoft.
     
  15. YoungXi

    YoungXi

    Joined:
    Jun 5, 2013
    Posts:
    63
    Having the same problem here... Trying to look deep into 'Addressables' and Visual Studio bugs me. Or maybe Unity PackageManager can import those Packages into 'Assets' folder as an option?
     
  16. horatiu665

    horatiu665

    Joined:
    Nov 22, 2012
    Posts:
    24
    For something constructive: how do you solve this need to navigate code, @okcompute_unity ? if you had to find the references of a script that resides in a package, to understand how the package works, or maybe to find where a particular value is assigned, do you have a way of navigating package code in your preferred IDE? or do you do it the 80's notepad way and keep everything in your head?

    I discovered that Rider has the ability to do what the OP was looking for, but that's not visual studio as I first thought...
    https://blog.jetbrains.com/dotnet/2018/09/19/unity-package-explorer-rider-2018-2/

    anyway that also costs money so I was hoping to find a free solution
     
  17. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi, I found that enabling "Preferences>External Tools>Generate all .csproj files." then "Assets>Open C# Project" makes VS code navigation works for all of packages. I tested with Unity 2020.1.b2. I hope that this workaround help you.
     
    longnu, vildauget, cdr9042 and 10 others like this.
  18. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Also works on 2019.3.13f1 :D Awesome, thanks ^^
     
    JNoon1 likes this.
  19. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    287
    Note that if you use Assembly Definitions, you'll need to have a top-level definition that includes references to the package assemblies you're using in order for this to work (but you should have that anyway).

    If you don't have any knowledge of the problem, probably best not to comment with your Unity account. It looks especially terrible when people come along later and find this mocking "sucks to be you" type of comment. Fortunately someone from the community found the solution despite you throwing in random red herrings about VSTU version numbers. And fortunately, as this is a community-driven forum, me criticizing a Unity employee's behaviour is perfectly acceptable.
     
  20. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    I wanted to be honest and let the community help this fellow. VSTU is not developed by Unity. This is a software developed by a third party. I don't use Visual Studio. I use a mix of Rider and Vim.

    Yes, I'm working at Unity. Yes, I have to be careful at what I'm saying. In this situation, if you understood "sucks to be you" from me, then I don't know what to say. I read what I wrote again and this is not what I'm understanding from the words I wrote. Maybe this is because English is not my native tongue?! Anyway, sorry if you felt that I was mocking you. I'll be more careful in the future.

    Regards,

    Pascal
     
  21. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Hello folks.

    - VSTU is only displaying files included in cs-projects, so you need to instruct Unity to generate proper projects.
    - For that you can go to Unity: Edit/Preferences/External Tools and check "Generate all projects" or select all package types you need depending on the version.
    - VSTU has a dedicated support for packages since v4.1.0.0. Please note that you need to use Visual Studio 2019. Visual Studio 2017 is only supported regarding critical security fixes. All new features are only coming to Visual Studio 2019. The full changelog is here: https://docs.microsoft.com/en-us/vi...og-visual-studio-tools-for-unity?view=vs-2019
    - Regarding VSTU, we improve support and fix bugs in every VS release, so if you can please always try to use the latest VS / VSTU (and the latest VS editor package if you are on 2020.x+).

    Regards
    Seb
     
  22. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    @okcompute_unity I didn't get your comment as mocking but it was pretty weird indeed that you chimed in without actual understanding of the domain :) no harm done, just unexpected. Suggestion for next time: point one of your colleagues to the issue as well, that would be very helpful.

    @sailro thanks for chiming in.
    Could you clarify who's responsible for maintaining the VS/VSCode packages that generate the actual csproj files?

    Because same as the VSCode unity package the VS unity package still has lots of issues around csproj generation. Things that break it include
    - renaming an asmdef
    - moving files between asmdefs
    - adding new packages
    - moving packages (e.g. embedding a package)
    - adding scripts while there are compile errors in unity (this for me is the worst one as this is where intellisense is needed the most)

    All of these require closing the external editor, selecting "Generate" in unity, then reopening. These are known to Unity for quite some time, but it seems responsibility for those issues is shuffled around between Unity and Microsoft. I'd like to gain a better understanding who's responsible for which area in this process.
     
    cdr9042, Baggers_ and burtonposey like this.
  23. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    226
    Would be nice to be able to select specific registry packages to generate a csproj files for. I have like 124 packages installed but only need to explore the code of a few of them.

    It would be nice to have an "auto-generate csproj when a file is opened" sort of feature and have that be Unity's default preference.
     
    ledbetterMRI and waltran like this.