A .dll file is included in the build when the only reference to it is enclosed in #if UNITY_EDITOR
Unity: Content Build
Fixed
2022.1.X
2021.3.X
2020.3.X
Won't Fix
2022.2.X
Version is not affected (fixed in https://ono.unity3d.com/unity/unity/pull-request/138055/_/scripting/fix-define-constraints-for-plugins).
Steps to reproduce:
1. Open the attached “1258702_ExcludeDLL 2.zip“ project
2. Open Assets/SampleScene.unity
3. Open Assets/Scripts/UseLibrary.cs
4. Change “#if !UNITY_EDITOR“ to “#if UNITY_EDITOR“
5. Go to File > Build Settings and press the “Build And Run“ button
6. Open the Editor.log file and search for “MyTestLibrary.dll“
Expected result: MyTestLibrary.dll file is not included in the build
Actual result: MyTestLibrary.dll is included in the build