-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unity separate generator project #155
Conversation
The main differences are: - Doesn't generate the attributes class in assemblies (and because of that doesn't require RegisterForPostInitialization) - Uses CodeAnalysis 3.8.0 - Doesn't throw exception when attribute types are missing - Skips Unity builtin assemblies For some reason more pragma warning disable are required when in a separate directory Fix missing type exception not ignored
Is there a chance we can adapt the main project to detect unity and adjust the logic?
Does unity define any MSBuild variable we can use in build.targets to downgrade the CodeAnalysis version?
Why is this needed? |
Unity has it's own compilation process and only accepts precompiled generators as dll unfortunately...
Because I disabled the attribute class generation because CodeAnalysis 3.8.0 doesn't support RegisterForPostInitialization, instead the user has to reference the Jab.Attributes.dll himself. Which to be honest I like better anyhow, why do you generate the Jab.Attributes class in every assembly in the first place? seems wasteful (Unity projects very often have 150+ assemblies) |
Gotcha, thank you for the context.
Usually, you only add JAb to one or two assemblies that need service provider. But I can see how Unity make this case worse. I'm not a fan of skipping assemblies by name and try-catching on types not found. What do you think about filtering out assemblies without known types early on in Generator.Unity? That way we don't need to hardcode any module names and the rest of the generating code can assume types are there. |
Ahh also something I forgot to mention, Unity doesn't let you add a generator only to specific projects only the entire Unity solution 🙃
You mean by adding And I have no strong opinions about skipping assemblies, I'll remove it if you prefer :) |
Yeah, something like:
Feel free to check for a single type in |
Isn't |
Ah, right, we don't care about embedded types in this case. |
src/Jab.Unity/Jab.Unity.csproj
Outdated
<NoWarn>$(NoWarn);RS2008</NoWarn> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? How will users get this dll then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unity users have only 2 options: downloading/building and dragging manually the dll into their Unity project or using an npm package (which I created here)
Unity doesn't support Nuget unfortunately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about https://docs.unity3d.com/Manual/upm-git.html ? Do you know what needs to be added to this repo for unity customers to be able to reference it via a git reference? Or should we add a minimal jab npm package with the generator dll only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can build the Jab.Unity.dll and Jab.Attributes.dll into any directory in this repository then we only need to add a package.json like this inside that directory and then users can install it using:
https://github.com/pakrym/jab?path=the_path_to_that_directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh and we need to add Unity specific meta file for each dll by opening them inside Unity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the meta file generation a one time operation or is it required for every new dll build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One time
Thank you @AlonTalmi! |
Thank you @pakrym 👍 |
I'd love it! Can we have the package definition right in the https://github.com/pakrym/jab/tree/main/src/Jab.Unity and then have CI do building and publishing? Happy to help with the CI part. |
Solves #138
The main differences between Jab.Unity and Jab.Roslyn3 are:
I also moved the generator scripts to a separate directory so they're not imported as part of the Jab.Common
(Which for some reason required me to add more pragma warning disable for RS1001)
In order to use inside Unity follow: https://docs.unity3d.com/Manual/roslyn-analyzers.html
Also requires the Jab.Attributes.dll