Version: 2019.2
Assembly Definitions
Managed code stripping

Assembly Definition properties

Click on an Assembly Definition Asset to set the properties for an assembly in the Inspector window.

Assembly Definition Inspector
Assembly Definition Inspector

Name

The name for the assembly (without a file extension). Assembly names must be unique across the project. Consider using a reverse-dns naming style, especially when an assembly could be used in more than one project. Note that Unity uses the name you assign to the Assembly Definition Asset as the default value of the Name field, but you can change the name as desired.

General

Allow ‘unsafe’ Code

Enable the Allow ‘unsafe’ Code option if you use the C# unsafe keyword in a script within the assembly. When checked, Unity passes the /unsafe option to the C# compiler when compiling the assembly.

Auto Referenced

Specify whether all the predefined assemblies should reference this Project assembly. When checked, the predefined assemblies reference all assemblies defined in the Project, which matches how precompiled assemblies (plugins) are referenced by predefined assemblies.

When you disable the Auto Reference option on a file, Unity will not automatically reference the file during compilation. This has no effect on whether it is included in the build. To control the Build Settings for plug-ins use Platform Settings.

Override References

Enable the Override References option to manually specify which precompiled assemblies this assembly depends upon. When you enable Override References, the Inspector shows the Assembly References section, which allows you to specify the references.

A precompiled assembly is a library compiled outside your Unity project. By default, assemblies defined in your Project reference all the precompiled assemblies you add to the project, which matches how the predefined assemblies reference all precompiled assemblies. When you enable Override References, this assembly only references the precompiled assemblies you add under Assembly References.

Note, to prevent a precompiled assembly from being automatically referenced by Project assemblies, you can disable its Auto Referenced option. See Plugin Inspector for more information.

Define Constraints

Specify the compiler #define directives that must be defined in order for an assembly to be compiled or referenced.

Unity only compiles and references a Project assembly if all the Define Constraints are satisfied. Constraints work like the #if preprocessor directive in C#, but on the assembly level instead of the script level. All the symbols in the Define Constraints setting must be defined for the constraints to be satisfied. You can also specify that a symbol must be undefined by prefixing it with a negating ! (bang) symbol. For example, if you specify the following symbols as your Define Constraints:

!ENABLE_IL2CPP 
UNITY_2018_3_OR_NEWER

the constraints are satisfied when the symbol ENABLE_IL2CPP is NOT defined and the symbol UNITY_2018_3_OR_NEWER IS defined. Or to put it differently, this assembly is only compiled and referenced on non-IL2CPP scripting runtimes for Unity 2018.3 or newer.

You can use any of Unity’s built-in #define directives or any symbols defined in the project’s Scripting Define Symbols Player setting. See Platform dependent compilation for more information, including a list of the built-in symbols. Note that the Scripting Define Symbols settings are platform-specific. If you use this setting to define whether an assembly is used, make sure that you define the necessary symbols on all the relevant platforms.

Assembly Definition References

Specify references to other assemblies that you have created using Assembly Definition Assets.

Unity uses these references to compile the assembly and also define the dependencies between assemblies.

The Use GUIDs option controls how Unity serializes references to other Assembly Definition Assets. When Use GUIDs is enabled, Unity saves the reference as the Asset’s GUID, instead of the Assembly Definition name. It’s good practice to use the GUID instead of the name, because it means you can make changes to the name of an Assembly Definition Asset without having to update other Assembly Definition files that reference it.

Assembly References

Specify references to any precompiled assemblies on which this assembly depends. You must check the Override References option in the General section to manually specify references to precompiled assemblies.

Unity References

To mark the assembly as a test assembly, enable the Test Assemblies option in the Inspector. Enabling Test Assemblies adds references to the unit.framework.dll and UnityEngine.TestRunner.dll libraries to the Assembly Definition.

When you mark an assembly as a test assembly, predefined assemblies (such as Assembly-CSharp.dll) do not automatically reference this assembly and the assembly is not included in builds.

To include test assemblies in a player build, use BuildOption.IncludeTestAssemblies in your build script.

Note: This option only includes the assemblies in your build and does not execute any tests.

Platforms

Set the platform compatibility of the assembly. Unity only compiles or references this assembly on the included (or not excluded) platforms.

Assembly Definitions
Managed code stripping