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?
This should be what is happening. What version of Unity are you using?
I’m using the 2018.3.10f1. I could see the csproj file generated but they were not added to the sln file.
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.
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.
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.
Could it be possible for visual studio?
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)
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.
Is there any update on this?
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.
It also works with Unity 2019.2.17. Thanks a lot for pointing this out!
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.
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
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
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.
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.
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.
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!
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.