How do you make a dll?

I want to put all my c# scripts into a dll. I read that you can actually do that from within mono develop. I haven’t had any luck finding a video or tutorial on the exact steps on creating one. Anyone have an idea?

From within MonoDevelop:

  • File > Create New Solution
  • Select C# Library

Then you can right click your project to select eventual options, and start adding folders, classes, and files. I suppose you can go on by yourself from here :slight_smile:
(also, remember that you can add more than one project to a single solution)

Start a new solution (C# Library type). Add the C# files you want included in the DLL. Build → Build All. The DLL will be in the solution directory\bin\debug (or \bin\release, depending on your active configuration).

After creating a new solution, I make the default class created inherit from MonoBehaviour. Then I add the line “using UnityEngine” at the top of the script. Then I go to Build/Build All and an error pops ups that says “The type or namespace ‘UnityEngine’ could not be found”. So I probably have to add it to the pjt some how. Do either of you know where I can find it, or what I have to do next?

Thanks for your quick responses.

You need to reference the UnityEngine assembly.

Okay, I added a reference to UnityEngine.dll which was located inside of the Unity application folder. And I successfully made a build in MonoDevelop. Then I imported the dll into my Unity pjt. Then I tried to place one of the scripts inside that dll onto one of my game objects, but I couldn’t find it in the “Component/Scripts/” menu… Any ideas?

You can’t add “Scripts” to your game objects that do not have a corresponding .cs or .js file in the Unity project. I don’t know why it’s like this, but it is.

This is sort of true. While not being able to do it via the menu - if your class inherits MonoBehaviour you can expand the DLL in your project hierarchy and the class will be there. From there you can drag and drop the “script” onto a GameObject.

Ah, okay. Thanks fholm, that clears things up.

EDIT:
@KelsoMRK: Huh, that’s weird. My dll contained a class that derived from MonoBehaviour, but I didn’t get the collapse triangle on my dll. Wonder why?

Dunno. Make sure your class name matches the file name.

I’ve heard this quoted before, but I have never seen it actually work.

How fortuitous! I was looking to do just this tomorrow and seeing this thread has me heading on the right track. A nice thread, many thanks.

  • Matt.

P.S. though obviously, even if you can’t drag&drop them, you can attach MonoBehaviours via code, even if they’re inside a DLL:

myGameObject.AddComponent<MyMonoBehaviour>();

But you will miss all the inspector goodies :stuck_out_tongue:

P.P.S. hey, just tried that “drag&drop directly from DLL” thing KelsoMRK was talking about. Never tried it before, but it actually works (using Unity 3.4.2f3)! Cool :slight_smile:

Weird that you guys were having issues with it. I’ve never had a problem with a MonoBehaviour in a library showing up.

I don’t know why, but this has never worked for me and I have tried on numerous occasions

Hi there, I have a small question regarding the usage of custom managed DLLs.

The managed DLLs contain basically assembled IL Code, so can I use the generated DLLs without any extra work on iOS, Android, eg. devices?

IIRC as long as the assembly is compatible with the specific runtime version of mono used on those devices, then yes. For iOS it needs to be able to be AOT-compiled for example, which all assemblies can’t. this is a case by case basis, test it for all assemblies you need.

Ok, thank you :slight_smile: