Building a DLL library in monodevelop

How do I do it. I believe I am very close, but I still haven’t got that cigar.

Below is what I have.

What I am wondering is why I can’t build it. Am I missing any assembly references?
Is the code wrong? Any help would be greatly appreciated.

I started by making a new solution in monodevelop, and using the Library defaults.

dll

using System;

using UnityEngine;



namespace dllTest

{

	public class GenericCode

	{

		public static int a = 0;

		

//		Generate a random number between min and max, including min and max

		public void GenRandom (int min, int max)

		{

			System.Random random = new System.Random();

			a = (random.Next(min, max +1));

		}

	}

}

unity

using UnityEngine;
using UnityEditor;
using System.Collections;

using dllTest;

public class test : MonoBehaviour {

	GenericCode gc = new GenericCode();
	
	void OnGUI () {
		if(GUILayout.Button("gen random"))
		{
			gc.GenRandom(0,10);
			int a = GenericCode.a;
			Debug.Log(a);
		}
	}
}

I still can’t get MonoDevelop to build the dll. When I click build, nothing is outputted.

… Once I delete the Unity dlls, it builds fine. But then I can’t use Unity commands. This seems dumb. I am probably making a very simple mistake.

Actually, its just when UnityEngine.dll is added.

Meh, I can do it in Visual Studio so its fine. But if anyone figures out the problem, I am all ears!

odd, should work in Mono also, works fine for me.

can some one provide a detail tutorial on it. text or video both will work.

I would be interested in how to build the dll as well. what is the command line for it?

it’s realy easy in visual C#, create a new class library project.
add a reference to the UnityEngine.dll in the project.
add your functions to the class.
build the dll and copy it in the assets folder.
call your functions from your script.

Does building such things into a dll offer any performance benefits?

i don’t think so.
the goal for me is just to be able to reuse code in different projects easily.

building a DLL is useful if you want to sell your work as a plugin, because it prevents others from easily viewing your source code

No, because it’s trivial to decompile DLLs. Anyway you should generally be providing source code regardless, since many people won’t buy without it. The primary reasons for using a DLL are 1) everything consolidated into one file, 2) double-clicking errors in the console goes to where it was called in your code, rather than the source code, which is much more useful when you’re actually trying to use the code as a regular user rather than as the developer, and 3) since they’re already compiled, having DLLs in your project adds nothing to script compilation times.

–Eric

In case anyone is still having trouble building a dll that includes unityengine.dll in mono, look here:

1 Like

There’s actually a really good argument for not supplying source code. It enforces that new features be requested by users and added by the original author to the source so everyone using the product can benefit.

No, not at all. I supply source code and it’s still the case that new features are requested by users and added by me. There’s no indication that having a DLL (only) would change that behavior. As I mentioned, it’s trivial to decompile DLLs anyway.

–Eric

1 Like