Hey everyone. With all the regressions to ECS generics, I’m hoping to turn to source generators to fix my problems and stop running into broken edge cases. Unfortunately, Unity makes me build source generators separately, and I have been having the roughest time just getting them to work at all (not even in Unity, though I’m trying to set them up in a way that would be compatible in Unity).
Some background, I’m using VS Studio 19 and Windows 10 as I’ve been procrastinating updates. I hope these aren’t the root of my issues.
I create a new class library project targeting .NET Standard 2.0. I then install Microsoft.Codeanalaysis.CSharp version 4.0.1 from Nuget (I’ve also tried 4.2.0 based on a rumor this was supported better, but same issue). I wrote an IIncrementalGenerator and it compiles fine. I then created a second project in the solution to test. However, when compiling the second project in the solution, I get the following error:
If I try to copy the DLL to a Unity project, I get a similar error about not being able to load the plugin due to missing dependencies. When using version 4.2.0, the version in the error message changes, but otherwise its the same issue.
I’m wondering if anyone can provide any insight or provide the steps they use for building and testing source generators?
Unity uses 4.0 and incremental source generators for IJobEntity in their latest releases. I checked that before going down the route of incremental source generators. I did find this link, which does explain the issue I’m having. Versions of source generator dependencies | Damir's Corner Although I don’t get why the source generator were able to compile if I don’t have working libraries on my system. And it also doesn’t really explain why the error also occurred in Unity, but I’m hoping a newer Visual Studio will solve the problem. That’s what I am doing right now. I’ll post again if I either run into more issues or get it working.
Would you please tell me more about how you made this to work?
What version of Roslyn / Visual Studio / Unity you used, so you could use Incremental Generator successfully?
I want to use Roslyn generators in my Unity project, but I want to use incremental generator instead of that old classic one. Any help would be greatly appreciated
I went through your post quickly and will read it carefully in the evening.
But can you please tell me one crucial thing? You used Unity version 2022.2.11 and it worked there?
And you finally used Visual Studio 2022, not the Visual Studio 2019, is that right?
Did you try to run the very latest stable build of VS 2022?
PS: From you documentation about generators, it doesn’t look simple at all, to make it work
Since 2022.3 has been out for a while, you should use it. It lets you access Microsoft.CodeAnalysis.CSharp 4.3.1. I’ve been using VS 2022 to build source generators for Unity for a while, no problem at all.
Source generator is not a simple topic. But would you mind elaborate on this?