Search Unity

How to add Assembly-CSharp reference to asmdef?

Discussion in 'Scripting' started by Lesha-VH, Nov 6, 2019.

  1. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    96
    I can not add reference to custom asmdef, because Assembly-CSharp it no in list.

    What workaround?
    I suspect just add asmdef to each top folder that contains scripts.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    Assembly-CSharp automatically has a reference to every asmdef-based assembly, so they can't reference it.
     
  3. Lesha-VH

    Lesha-VH

    Joined:
    Jul 3, 2012
    Posts:
    96

    Attached Files:

  4. mbentley3123

    mbentley3123

    Joined:
    Jul 2, 2020
    Posts:
    1
    I don't think so.
    1) I checked, and my project creates an EditModeTests project using an asmdef file. Assembly-CSharp.csproj does not have a reference to it.
    2) Currently, I am trying to access the code in Assembly-CSharp from EditModeTests and can not seem to get it to put a reference in. So, neither project can see the other.
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    You're right, assemblies marked as test assemblies can't be referenced by Assembly-CSharp. That's for obvious reasons - test assemblies are not included in builds, so your build would fail.

    So I was wrong back last November!
     
  6. DELHOMMEAU_Antoine

    DELHOMMEAU_Antoine

    Joined:
    Nov 25, 2019
    Posts:
    4
    Hello,
    I'm facing the same problem.
    I downloaded an asset where classes are in a custom assembly. I need to edit some of those classes but I can't access classes from Assembly-CSharp.
    Any idea how to do so?
    THX
     
    Pavlov_Oleg likes this.
  7. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    This is the wrong approach all together. The Assembly-CSharp should be seen as the root node. This is your actual Unity application. Seperate assemblies are seperate isolated compilation units which are ultimately used by AssemblyCSharp. Nobody else will be using "Assembly-CSharp", this is only "used" by the Unity engine itself. You try to mix and break out of the isolation that was put in place on purpose. Assemblies can not have circular dependencies. As Baste said, the "Assembly-CSharp" will reference all other (runtime) assemblies automatically. It's the ultimative root of the developer controlled scripting environment.

    So you probably do understand the concept how that assembly you were talking about is supposed to be used. If you need to implement some sort of bi-directional communication, you have to use interfaces, delegates or other means that decouple your assemblies.

    Of course another solution is to simply remove the assembly definition file and just keep all the files inside the Assembly-CSharp as usual. In that case you can do whatever you want.
     
    AlMartson likes this.
  8. DELHOMMEAU_Antoine

    DELHOMMEAU_Antoine

    Joined:
    Nov 25, 2019
    Posts:
    4
    I was thinking one way, you opened my eyes.
    Thank you!