Search Unity

Validating references in custom assembly definition

Discussion in 'Editor & General Support' started by nickfourtimes, Mar 26, 2021.

  1. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    219
    Hi,

    I've created some custom assembly definitions for our project, and they have various references to other assemblies (Unity packages, other plugins, &c). I'm writing some editor scripts just to verify that our main assembly – call it MyGame.asmdef – has valid references listed. For instance, for testing purposes, I created a placeholder assembly, added it to MyGame.asmdef's references, then deleted the assembly from disk; now the inspector shows simply
    None (Assembly Definition Asset)
    in the inspector field for that reference.

    So far, I've written some quick code just to get a handle on all references in the project:

    Code (CSharp):
    1. var assemblies = CompilationPipeline.GetAssemblies();
    2. for (int i=0; i < assemblies.Length; ++i) {
    3.     var refs = assemblies[i].assemblyReferences;
    4.     foreach (var reference in refs) {
    5.         Debug.Log("i am " + assemblies[i].name + " and i ref " + reference.outputPath);
    6.     }
    7. }
    In my test example however, the output is
    i am MyGame and i ref Library/ScriptAssemblies/UnityEngine.UI.dll

    I'm not totally sure why it lists a reference to UnityEngine.UI – was it auto-populated when I deleted the placeholder assembly? if so, why wasn't the inspector updated?

    Is there a better way to validate all the references in a given assembly?