Skip to content

Ability to set the DefineConstraints of packages#733

Open
kochounoyume wants to merge 7 commits into
GlitchEnzo:masterfrom
kochounoyume:master
Open

Ability to set the DefineConstraints of packages#733
kochounoyume wants to merge 7 commits into
GlitchEnzo:masterfrom
kochounoyume:master

Conversation

@kochounoyume

@kochounoyume kochounoyume commented Oct 16, 2025

Copy link
Copy Markdown

This is the implementation of feature #639 .

Enabling the DefineConstraints setting allows you to, for example, set restrictions on UNITY_EDITOR definitions for specific packages and exclude them from the build output.

This proves extremely useful within the Unity environment.

Refer to the existing implementation; #507

Comment thread src/NuGetForUnity/Editor/Configuration/PackageConfig.cs Outdated
Co-authored-by: JoC0de <53140583+JoC0de@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 defineConstraints attribute in packages.config.
  • Apply defineConstraints to imported package DLLs via NugetAssetPostprocessor.
  • Document the new defineConstraints setting 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.

Comment on lines +295 to +298
if (!string.IsNullOrWhiteSpace(packageConfig.DefineConstraints))
{
plugin.DefineConstraints = packageConfig.DefineConstraints.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}

@JoC0de JoC0de Apr 19, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point two options:

  1. We accept this behaviour so user can manually set DefineConstraints in 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 from package.config it will not be applied.
  2. We use the suggestion from Copilot -> a user that has set DefineConstraints in the .meta manually needs to mirror the setting to the package.config

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Comment thread src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs Outdated
Comment thread src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants