Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Add a reference to Assembly-CSharp in assembly definition file

Discussion in 'Scripting' started by mnarimani, Jul 18, 2018.

  1. mnarimani

    mnarimani

    Joined:
    Mar 27, 2017
    Posts:
    214
    Hi. How can I add a reference to predefined assemblies when using assembly definition files?

    I can't use unity packages when I move my scripts to another assembly using asmdf files.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,621
    You can't. The predefined assemblies are always the last to compile.

    If you need to reference code from Unity packages, and they're not available, those packages probably ship with their own assemblies, and instructions on how to include them. What packages are you struggling with?
     
    mnarimani likes this.
  3. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    729
    as far as I understood these assembly definition files you can use them only or not use them at all. So you cannot mix "predefined assemblies" with custom assemblies. Instead you have to put the assembly definition files all over your project including the used third party assets... And do not forget to add asmdf files to all the editor folders with the right compile settings...

    All this is designed without thinking about the real world I think... For me they are totally useless and I use my own tool which splits the assembly into several projects (unfortunately I cannot make use of the good parts of the asmdf approach: improving compile times and excluding projects from certain platforms).

    Edit: here some additional thoughts: https://forum.unity.com/threads/assemblydefinitionfiles-good-idea-but-not-usable-in-praxis.538739/
     
    leni8ec and mnarimani like this.
  4. mnarimani

    mnarimani

    Joined:
    Mar 27, 2017
    Posts:
    214
    I was struggling with TextMeshPro. But I finally could fix it. The problem was that when you try to add a reference to assembly definition, the assembly definition files from packages doesn't show up in the pop up window. So I didn't know TextMeshPro had assembly definitions inside.


    It definitely needs improvement.
    At least we need a button to quickly mark assemblies as "Editor Only".
    Another enhancement that I think is really necessary is that Unity should generate Editor Only assembly definitions for all Editor folders with click of a button. Existing projects (and even relatively new ones) might have dozens of Editor folders. It's such a pain to create asmdf files for each one of them by hand ( Which is what I did :| ).
     
    leni8ec likes this.
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,621
    That's just simply not true.

    Code under assembly definition folders work like the plugins folder in the old system. Your default assembly can reference them, but not the other way around. The only difference is that the different assemblies can reference each other in the same fashion, which gives a more granular approach if that's neccessary.

    Assembly definitions isn't special. Any non-unity .NET project in the world can do exactly the same thing by splitting code into different assemblies. Most other languages do too.[/QUOTE]
     
  6. Simon-O

    Simon-O

    Joined:
    Jan 22, 2014
    Posts:
    34
    That's fine unless you're trying to create a test assembly which references the main codebase but isn't deployed with a build...
     
unityunity