Ability to set the DefineConstraints of packages#733
Conversation
Co-authored-by: JoC0de <53140583+JoC0de@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds support for configuring Unity PluginImporter Define Constraints per NuGet package via packages.config, enabling conditional referencing based on scripting define symbols (feature #639, similar to #507’s autoReferenced support).
Changes:
- Parse and persist a new
defineConstraintsattribute inpackages.config. - Apply
defineConstraintsto imported package DLLs viaNugetAssetPostprocessor. - Document the new
defineConstraintssetting in the README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/NuGetForUnity/Editor/NugetAssetPostprocessor.cs | Applies package-level define constraints to Unity plugin importer settings. |
| src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs | Loads/saves defineConstraints from/to packages.config. |
| src/NuGetForUnity/Editor/Configuration/PackageConfig.cs | Adds DefineConstraints property to package config model. |
| README.md | Documents how to use defineConstraints in packages.config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!string.IsNullOrWhiteSpace(packageConfig.DefineConstraints)) | ||
| { | ||
| plugin.DefineConstraints = packageConfig.DefineConstraints.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); | ||
| } |
There was a problem hiding this comment.
Good point two options:
- We accept this behaviour so user can manually set
DefineConstraintsin the unity settings (if he commits the .meta file to git) even when he doesn't use the setting in package-config. But unfortunately this will lead to the behaviour that a if a user uses the setting and later removes it frompackage.configit will not be applied. - We use the suggestion from Copilot -> a user that has set
DefineConstraintsin the .meta manually needs to mirror the setting to thepackage.config
There was a problem hiding this comment.
@JoC0de
I’m sorry it took me so long to notice.
Also, thank you for addressing the missing details so thoroughly.
So, regarding the two options this time, I agree with the implementation proposed by Copilot. While the first method seems convenient because it can be configured manually in Unity, considering the concerns mentioned earlier and the implementation required to address them, I question the value of investing that much effort into an option that isn’t used very frequently, as well as the maintenance required for that implementation. It might be a bit of a hassle for users, but isn’t Copilot’s proposed method the more reasonable choice?
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This is the implementation of feature #639 .
Enabling the
DefineConstraintssetting allows you to, for example, set restrictions onUNITY_EDITORdefinitions for specific packages and exclude them from the build output.This proves extremely useful within the Unity environment.
Refer to the existing implementation; #507