Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Managed DLLs with Define Constraints aren't linked correctly during build

Discussion in 'Scripting' started by Andrew-Carvalho, Jul 28, 2023.

  1. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    39
    Hi! I'm running into compilation errors during builds and was hoping to get some insight.

    Some context for what I am running into:
    I have a package of my own that includes an assembly definition and a few scripts, as well as managed assemblies (precompiled dlls) from an open source project. The managed dlls are set to not be auto referenced, are set to be available in Editor and the target platform (Desktop in this case), and are referenced by my assembly definition in the Assembly References section.

    This package is is not included in all builds. My assembly definition includes a define constraint and the managed dlls also have this same define constraint (along with a logical OR with UNITY_EDITOR so that is remains available in the Assembly Definition's Assembly References dropdown list).

    The bug I am seeing:
    When making builds, I use BuildPipeline.BuildPlayer( BuildPlayerOptions ) and pass in the required scripting define inside the BuildPlayerOptions.extraScriptingDefines property. This is my preference as I do not want this define to ever accidentally be left serialized in the player settings.

    When making builds, the scripts in the assembly definition fail to compile because it can't find the code from the referenced managed dll, even though they share the same constraints.

    I know that everything is set up correctly because manually adding the preprocessor define (either by typing it into player settings or using PlayerSettings.SetScriptingDefineSymbolsForGroup) allows the build to compile correctly.


    Is this a bug or am I not using the BuildPlayerOptions.extraScriptingDefines as intended?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,711
    The DLL will only have one "baked" configuration of code.

    This is set by the compiler at the time you compile the DLL.

    Nothing you set in scripting defines is even considered when looking at a DLL.
     
  3. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    39
    While I appreciate the help, none of this above is correct. You may be confusing a Native dll and a Managed dll.

    Managed libraries are compiled C# and are cross platform, running on the VM or going through IL2CPP the same as regular C# scripts. Assembly definitions are generating managed dlls at compile time. As I mentioned in my post, everything works when I manually type in the scripting define.

    This is seen when importing and selecting a managed dll in a Unity project. The inspector has almost identical properties to an assembly definitions.
    manageddll.png


    What I am looking for is a solution to the build errors that occur only when passing the scripting define into the BuildPlayer call using the extraScriptingDefines property
    .
     
    Kurt-Dekker likes this.