Search Unity

Feedback Could Unity add csproj of each package project into the solution file?

Discussion in 'Package Manager' started by jayatubi, May 15, 2019.

  1. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143
    The vs sln file generated by Unity editor only contains the project under Assets folder. However, there are also csproj files for each package project next to the sln file. Could Unity editor involve these package project csproj files into the sln as well?
     
  2. mathieur

    mathieur

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    31
    This should be what is happening. What version of Unity are you using?
     
  3. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143
    I'm using the 2018.3.10f1. I could see the csproj file generated but they were not added to the sln file.
     
  4. mathieur

    mathieur

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    31
    That's strange. I just tested it and it does seem to work, albeit I am using 2018.3.12f1. If you have a simple project which reproduces the issue I could take further look.

    Screen Shot 2019-05-16 at 10.58.17 AM.png

    Screen Shot 2019-05-16 at 10.58.26 AM.png
     
  5. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143

    Maybe you misunderstood what I meant.

    I meant the projects from the Asset folder, such as my own code or asmdef project, would be generated and added into the solution file.

    But the projects from the packages, which were installed via Package Manager, would NOT be added into the solutions file.
     
  6. mathieur

    mathieur

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    31
    Ah! I see what you mean. So I believe that only the in-development packages (eg: those located inside your project's Packages folder) will generate a csproj file. The read-only packages (eg: those installed via package manager window) will indeed not create a csproj. There are ide such as Jetbrains Rider which does have support to automatically add the read-only projects to your solution, but that is dependent on which ide you use.
     
    SugoiDev likes this.
  7. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143
    Could it be possible for visual studio?
     
    OndrejP likes this.
  8. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    This is essential for development, because it allows you to use Go To Definition (and other IDE features) and see the implementation easily.

    Also it fixes the issue with "missing" XML documentation in referenced packages.
    (e.g. Unity.Entities contains a lot of documentation comments, but they won't show because there's no Unity.Entities.xml in Library\ScriptAssemblies)
     
    Last edited: May 19, 2019
    Erothez and De-Panther like this.
  9. Erothez

    Erothez

    Joined:
    May 27, 2015
    Posts:
    20
    Packages using csproj with default unity folder layout stuff would be nice, been doing some stuff with file:// packages and being able to reference/find stuff and see comments has been a god send.
     
    OndrejP likes this.
  10. AdminOh

    AdminOh

    Joined:
    Feb 11, 2016
    Posts:
    23
    Is there any update on this?
     
  11. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    This was added in (I think) 2019.3. Enable the "Generate all .csproj files" option in Unity's preferences under "External Tools".

    After enabling the option, you need to get Unity to regenerate the project, e.g. by selecting "Assets" » "Open C# Project". You then should see a lot more csproj files in your Unity project from all your package's assembly definitions.

    When enabling this option and using VSCode, the documentation for all packages is displayed and go to definition jumps directly to the source code.

    I did run into an issue where the option would be forgotten and I hat to uncheck, recheck and then regenerate the project to enable it again.
     
    Rallix and OndrejP like this.
  12. AdminOh

    AdminOh

    Joined:
    Feb 11, 2016
    Posts:
    23
    It also works with Unity 2019.2.17. Thanks a lot for pointing this out!
     
  13. AdminOh

    AdminOh

    Joined:
    Feb 11, 2016
    Posts:
    23
    Unfortunately the functionnality doesn't work properly.
    - The first time I generate all the csproj, they appear fine in Visual studio.
    - If I open Visual Studio a second time, the other packages does not appear anymore in Visual Studio. Even though I can see the csproj files in Windows Explorer.

    upload_2020-1-31_10-15-47.png

    upload_2020-1-31_10-15-57.png
     
  14. ethan_jl_unity

    ethan_jl_unity

    Unity Technologies

    Joined:
    Sep 27, 2018
    Posts:
    104
    Hi there,

    Thank you for your feedback. Would you mind submitting a bug? More details in steps to reproducing would be really helpful!

    Thanks!
    Ethan
     
  15. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    @ethan_jl_unity

    I'm also seeing this, csproj generation is entirely messed up - for months now. Happens everywhere from new projects from scratch to existing projects. Sometimes deleting all sln+csproj files, switching to VS Code, opening the sln and switching back to VS 2019 works. Sometimes the reverse (switching to VS 2019 to repair sln in Code).

    Reported a (new) case about this.
    (Case 1221734) Csproj file generation excludes Packages despite "Generate all csproj" being active

     
  16. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    35
    Just double checking here, in case I'm misunderstanding, but it is expected that the "Generate All .csproj files" option in Preferences -> External Tools should be generating the csproj files for Packages that were downloaded into the PackageCache? If so, I am not seeing this occur on 2019.3.3f1. I have yet to try in 2019.2.
     
  17. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    It's supposed to generate all so that developers can step through package code, one of the main advantages of packages. As with the above bug report (which happens daily), sometimes it does that but most of the times not.
     
  18. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    35
    I see. So my understanding of what it's meant to do is correct.

    For what it's worth, I ended up trying it in 2019.2.17f1 and I reproduced the exact issue that you've listed. All the csproj files were generated. I opened up the solution in Visual Studio for Mac and I could see all the projects in there (only when the "Show Unity Project Explorer" option was disabled. It was not visible when that was on). But then at some point the PackageCache projects all disappeared from the solution. I don't know what caused it. I didn't close/reopen the solution. It just vanished.

    From what I saw here, there are two places of issue: the first being that I couldn't see the projects with the Show Unity Project Explorer option on. I suspect this maybe a Visual Studio Tool for Unity issue. But the second issue is most likely a Unity issue, as you've described. Do you happen to have an Issue tracker link for your bug? I tried searching with your case ID, but I could not find it.

    The other issue that I'm seeing is that when I try the "Generate all .csproj files" option in 2019.3.3f1, I don't even get the .csproj files for the PackageCache packages generating. So that sounds like another bug on top of what you've found.
     
  19. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    It seems that the VS Code extension generates the csproj/sln, but Visual Studio 2017/2019 extension doesn't.
    @LeonhardP could you follow up with the bug report and figure out whether there's a workaround? Thank you!
     
  20. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    So I took a closer look at the issue, turns out the Visual Studio Code package 1.1.4 and lower only applies the setting of «Generate all .csproj files» when the preferences window is open. If the checkbox is not visible and the scripts are being reloaded or you restart Unity, the setting defaults to off. Only when you then open the «External Tools» preferences will the setting be applied properly.

    But version 1.2.0 of the Visual Studio Code package came out a while ago and fixes this issue. It's not yet verified (at least for 2019.3) and therefore won't show up as an update, you'll have to select it manually.
     
    fherbst likes this.
  21. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    111
    Last edited: Mar 24, 2020
    _met44 and jawad_ahmad like this.
  22. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    35
    This is great news! However, will 2019.3 (or 2019.4 even for that matter) see the fix? The IssueTracker ticket you linked mentions that 2019.3 is an affected version and as far as I can tell, the VS Package you're referring to is a 2020.1+ package only and is not available for 2019 (I'm assuming it was part of the 2019 editor code base, but was then spun off as a package for 2020).
     
  23. Domas_L

    Domas_L

    Unity Technologies

    Joined:
    Nov 27, 2018
    Posts:
    111
    The fix is planned to be backported to 2019.3, but it might take a bit longer for it to appear.
     
    _met44 and jawad_ahmad like this.
  24. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    35
    I'm not sure where's the best place to ask this but given this issue is somewhat linked to the topic here, I figured I might as well try here!

    I installed 2019.3.12 and I was happy to see that the fix for generating all the .csproj files has finally made it's way there.

    After regenerating the csproj files, it was great to see all the packages in there! However, I started seeing that VS was complaining that it was unable to find references to many Unity objects, which were all fine before. I know the code was okay because everything was compiling.

    Looking deeper into the issue, I noticed that the project references all have the ReferenceOutputAssembly tag set to false for any assembly that is referenced by project, like so:

    <ProjectReference Include="Unity.RenderPipelines.Universal.Editor.csproj">
    <Project>{A310FB9C-2715-5DC5-9006-D786D1D0DFA2}</Project>
    <Name>Unity.RenderPipelines.Universal.Editor</Name>
    <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>

    As a test, I manually edited the csproj file to remove this option (I could not see how to do it in VS itself), and low and behold VS could reference the objects that were defined in this assembly, as expected.

    This is definitely a 2019.3.12 change as it does not occur in 2019.3.10.

    I don't know what sets this option and I'm assuming it occurs in the csproj generation code. I'm hoping someone from Unity can explain the reason behind this change? It's somewhat annoying because firstly, my code in VS is now littered with error messages, and secondly, I can't use Find Reference Go to Declaration feature that I've been longing for since wanting to generate all the csproj files!

    When comparing to a csproj file generated in 2019.3.10, any project references there does not have the ReferenceOutputAssembly tag, so this is definitely something new.
     
    fherbst likes this.
  25. Erothez

    Erothez

    Joined:
    May 27, 2015
    Posts:
    20
  26. reuno

    reuno

    Joined:
    Sep 22, 2014
    Posts:
    4,929
    Could someone from Unity confirm that this is a bug, and is gonna be fixed?
    Or is this the new expected behaviour?
     
  27. jawad_ahmad

    jawad_ahmad

    Joined:
    Apr 28, 2017
    Posts:
    35
    Thank you for this! I will use that thread for any follow up questions/comments. I will be curious to know if someone from Unity can comment on the matter. It seems to be a conscious decision, and so I hope someone can explain the rationale behind it.
     
  28. jpvanoosten

    jpvanoosten

    Joined:
    Nov 20, 2009
    Posts:
    50
    I'm using Unity 2022.3.7 with Visual Studio 2022. The preferences to generate .csproj files for registry packages works great! But a little too great... Is there a way to to add only a few packages? For example, I only want to add the CesiumEditor and CesiumRuntime registry packages to the solution in Visual Studio. Is there a way to only add a few registry packages?
    upload_2023-11-29_13-37-14.png