Unable to export package depending on UI Elements

mac Big Sur 11.6
Unity 2020.3.20f1
com.unity.ui 1.0.0-preview.18

I’m trying to export a package with an asmdef that has a reference to

"references": [
        "UnityEngine.UIElementsModule"
],

but Unity cannot create it. Unity hangs (forever) after I type the package name and press save.

I’ve attached the project if anyone can provide insight. The package is pretty bare (a single script and the .asmdef). The important file is the .asmdef which is also attached (renamed to UIElementsSample.txt).
7570066--937324--package-with-ui-elements-structure.png

There seems to be some kind of error that flashes intermittently while the editor is open but it isn’t persistent so I’m unable to read what it says.

7570066–937321–uielements-package.zip (37.2 KB)
7570066–937327–UIElementsSample.txt (393 Bytes)

Have you tried removing the check on “Auto Referenced” on your asmdef? I suspect that could be impacting this process.

I tried it twice. Still hangs until I force quit the app. A dialog flashes but it closes so quickly I can’t tell what it’s trying to alert.

It was due to this line in the script [RequireComponent(typeof(UIDocument))].
Don’t know why this prevents a package from being exported but oh well. I’ll work around it.

[RequireComponent(typeof(UIDocument))] breaks exporting packages even when it is outside of an assembly definition (package). Hopefully it’ll get fixed in a future update.

Ok. Seems like after preview.14 an assembly definition is required to use UI Elements. Not so user friendly but oh well. See UI Toolkit migration guide - Unity Engine - Unity Discussions for instructions and information.

Exactly, in order to guarantee dependency order is respected, we need an Assembly Definition asset in the project if you’re using the UI Toolkit package. This would not be necessary if you were using Unity 2021.2+ because you don’t need the package with those versions (Runtime support is built in).