Search Unity

Errors Creating an External .dll for Unity3d

Discussion in 'Scripting' started by ATMEthan, Aug 31, 2018.

  1. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    Hello,

    I'm trying to create a .dll of code shared across multiple projects. But I'm running into missing directive/assembly reference errors in Visual Studio 2017. This is what I have done so far...

    1. Created a ClassLibrary(.NET Standard) project
    2. Added references to UnityEngine.dll and UnityEditor.dll via the Reference Manager. I add the .dlls from this location: C:\Program Files\Unity\Hub\Editor\2017.3.1f1\Editor\Data\Managed
    3. Copied and pasted my shared scripts into the solution
    4. Press build and tons of errors generate(these are at of the end of the post)

    I'm generally stumped here b/c this is new territory for me and I haven't been having any luck trying to research answers myself. If more information is needed please ask and I'll do my best to get it to you.

    Another secondary question is... can I compile a script that derives from MonoBehavior into an external .dll?

    Thanks

    Here's a few:
    Severity Code Description Project File Line Suppression State
    Error CS0234 The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) ATMUnityFramework C:\Users\Unity\Documents\Visual Studio 2017\Projects\ATMUnityFramework\ATMUnityFramework\ATMUtilities\Runtime\Helpers\DebugUI.cs 15 Active

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'GraphicRaycaster' could not be found (are you missing a using directive or an assembly reference?) ATMUnityFramework C:\Users\Unity\Documents\Visual Studio 2017\Projects\ATMUnityFramework\ATMUnityFramework\ATMUtilities\Runtime\Helpers\DebugUI.cs 79 Active

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?) ATMUnityFramework C:\Users\Unity\Documents\Visual Studio 2017\Projects\ATMUnityFramework\ATMUnityFramework\ATMUtilities\Runtime\Helpers\DebugUI.cs 240 Active

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?) ATMUnityFramework C:\Users\Unity\Documents\Visual Studio 2017\Projects\ATMUnityFramework\ATMUnityFramework\ATMUtilities\Runtime\Helpers\DebugUI.cs 254 Active
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,692
    I would recommend instead putting all the shared code in another git repository and then add it as a submodule specifically where you want it right in the Unity project.

    DLLs can obviously be done under Unity but they always seem to endless irritations when you are using them for simple shared code, rebuilding them a lot, fiddling, tweaking, etc.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,890
    There are other Unity dlls that you may have to reference. Not everything is in UnityEngine and UnityEditor.
     
  4. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    That's a great idea and we already do that. It's just that sometimes a client requires we deliver the entirety of the project to them. So in cases like this we would like to protect our internal assets which is why we are looking into creating DLLs.

    This might come off as rude and I'm not trying to be. But that's a very obvious observation. Do you have any specifics on your statement? I tried looking for a UnityEngine.UI DLL but I didn't find anything that matches the name exactly. I know in location "...Editor\Data\Managed\UnityEngine\" There are many UnityEngine.X DLLs. I guess I can start adding them and just hope it compiles.
     
  5. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    Well... I fixed the UnityEngine.UI missing references by adding this dll. "...\Editor\Data\UnityExtensions\Unity\GUISystem\UnityEngine.UI.dll"
     
    CodeSmile likes this.
  6. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    Mmm...

    Anyone know where I can locate the XR dll? I'm using Unity 2017.3.1f1? I'm missing references for XRNodeState and XRNode. I've added "...\Editor\Data\Managed\UnityEngine\UnityEngine.VRModule.dll" as well as "...\Editor\Data\UnityExtensions\Unity\UnityVR\Editor\UnityEditor.VR.dll" and those both didn't work.

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'XRNodeState' could not be found (are you missing a using directive or an assembly reference?) ATMUnityFramework C:\Users\Unity\Documents\Visual Studio 2017\Projects\ATMUnityFramework\ATMUnityFramework\ATMUtilities\Runtime\XRUtility.cs 139 Active

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'XRNode' could not be found (are you missing a using directive or an assembly reference?) ATMUnityFramework C:\Users\Unity\Documents\Visual Studio 2017\Projects\ATMUnityFramework\ATMUnityFramework\ATMUtilities\Runtime\XRUtility.cs 152 Active
     
    Last edited: Sep 4, 2018
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,890
    I don’t know it. But try ILMSpy tool. You can open .net dlls or exes with it and inspect its types.
     
  8. ATMEthan

    ATMEthan

    Joined:
    Dec 27, 2012
    Posts:
    54
    I stripped out the unnecessary XR utilities from my scripts and was able to compile the .dll. I suspect the issue was some of these scripts are written in 2018 and above and have different references. I was using my scripts with 2017.3 and adding references to the 2017.3 dll libraries not the 2018 dll libraries.