Search Unity

Assembly Definitions (asmdf) - When a library is recompiled the references are also recompiled?

Discussion in 'Editor & General Support' started by hedgehog90, Jan 4, 2018.

  1. hedgehog90

    hedgehog90

    Joined:
    May 18, 2016
    Posts:
    27
    This doesn't make any sense to me. When I make a change to a script in one library (test.asmdef) with several references to other asmdef libraries, the references also get recompiled.
    I can tell by the length of time the spinner spins in the bottom right and by looking at the datemodified of the dlls in Library/ScriptAssemblies.
    In the end I save barely any time using this new feature.

    Have I misunderstood something?
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    That shouldn't be how it works. If assembly A has a reference to assembly B, then recompiling B should cause a recompilation of A, not vice versa.

    Of course, changing any code in any assembly will recompile scripts in the "main" assembly named Assembly-CSharp (containing everything that's not in a asmdef folder), as that assembly implicitly depends on all other assemblies.
     
  3. hedgehog90

    hedgehog90

    Joined:
    May 18, 2016
    Posts:
    27
    Sorry, that's what I meant.
    I still don't understand why any library referencing the recompiled library needs to be recompiled as well though.

    I have a project file structure whereby I consider the main project assets or any self-contained utilities that I've built - as separate libraries / addons.
    So I have one folder called GP - essentially a package name made from my studio's initials - containing several libraries that I've built for myself that can be used across several projects.
    For the current project I'm working on, the scripts and other assets that pertain to the game are in a separate folder through a similar principle.
    If we consider these both libraries - GP.dll and Game.dll - then Game.dll references GP.dll.
    I hoped that I could recompile GP.dll without automatically recompiling Game.dll, but that doesn't appear to be possible.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    It is possible in C# to swap a dll dependency with a different one without recompiling, but that's not the default behaviour. See here.

    I'm guessing that what Unity's doing is taking the conservative route - it's quite likely that changing an assembly's dependency will require a change to the assembly itself, so it's recompiled just to be sure.

    I'm not quite clear on the further details, pinging @lukaszunity, so seems to be on the development team for the feature.
     
  5. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    One pretty good reason for the default behaviour to always recompile the referencing assemblies is behaviour dependent on the metadata of the referenced assembly. One such example is default values for function/method arguments. They are compiled in at the calling site, so if you recompile just the dependency they will not be updated.
     
    Baste likes this.
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Another example is const values, which has the same behaviour.