Assembly Definition in Editor folder

I am trying to struct my source by Assembly Definition files.
When it come to a Editor folder case. It seems all script are included in none-editor dll, with parent or child folder of .asmdef file named “Editor”.
And event the folder is Editor-script only and name “Editor”, if there is any .asmdef file in the folder.
Build process will not ignore it, and generate UnityEditor reference error.
Do this mean Assembly Definition files can not be used with editor script?

@lukaszunity

I found the setting here. Just not documented.

I am trying to implement assembly definition files for a larger project with many external dependencies. I find a large number of packages that now require separate asmdf’s for their editor folders and oftentimes the respective folder contains only one script. It is a cumbersome task and it does not feel right.

If I were to reimport the packages, I have to make sure to keep these files. If somebody else from my team imports a new package, he is forced to setup the assemblies and that is quite a technical task that I rather not have people do.

I was trying to clean up the project by splitting the assemblies, but now I have dozens of them and it feels like I achieved the opposite of what I intended.

Is there a different way of going about this? What is the idea here? I don’t get it.

Build times are not thaaat much of an issue, so for now I will keep most things in the default assembly and thereby have Unity autodetect the editor folders.

I have created a script that disables all assembly definition files before building the project and reenables it after the project builds, since i’m only interested in reducing compile time. When they fix this behaviour than I can delete my script

Did you manage to resolve the issue?

The docs for .asmdef files are available here, let us know if you find them lacking.

I’ve come up against this issue as well, and I have multiple 3rdParty tools. Its cumbersome alone to have to add an editor.asmdef for each editor folder, but its even worse that the tool isn’t smart enough to recognize multiple editor.asmdef files and create one assembly for it. Instead, each has to have a unique name.

I think it would be a very easy fix to have the assembly definitions recognize multiple .asmdef of the same name and add them all to one assembly. This way 3rdParty developers could simply add a editor.asmdef to their editor folder and uniform behaviour would be achieved.


EDIT:

One gotcha is that you need to check the “Test Assemblies” box for each editor.asmdef, to ensure it can access the UnityFramework for includes.

Another is that if you are using asset bundles built from a different project, and any of those assets have scripts attached to them, you need to make sure the other project has the same assembly definitions setup, otherwise when you stream the assets in, the scripts wont be found.

I also found that you can name the .asmdef files the same (Editor.asmdef), but in the inspector give them unique names. This is convenient if you want to find all of them when searching in the Project window.

Because I tend to prototype editor codes outside of Editor folders, I had circled almost all of my editor scripts with #if UNITY_EDITOR and endif as a fail-safe. These still work within an assembly.

Until then, this will be a good-enough solution for me.

This post comes up as first for me for when searching for resolution on this topic and I will therefore post my findings here:

What causes the problem?

When making an assembly definition all selected files and folders will be complied into the .DLL including the Editor folders/files. This is fine when you are in the editor as they still have a reference to the UnityEditor .DLL. As soon as you try to build you will encounter a ton of errors because the editor folders/files will now lose their reference to the UnityEditor assembly.

What can we do to resolve this?

As the OP has noticed you can mark your editor folders/files under their own assembly reference so that they are only included in the editor. However, this does not solve everything as you may notice that you continue to get other errors, because your editor files/folders now have no reference to the parent assembly, therefore you must remember to add a reference in the “References” section of the assembly definition to the parent assembly.

Please find a nice description of this issue and solution by Stewart L. McCready here.