- Home /
How is it best to distribute a complex unity project to other devs as asingle dll
I have a complex Unity project that I would like to distribute to a couple of other devs. They need to be able to write some new classes that subclass a particular class in the project.
However it's a requirement that the code content of the main project itself, preferably including the class they need to subclass, is not accessible to the devs. [EDIT: It's only the source code they can't access. They can still use the class, and will have documentation.]
Ideally the project I distribute would include one dll that contains the all of the classes from the original project.
The approach I have taken is as follows (it may be overly simplistic - I've not worked with .NET outside a Unity context)
1) Take the original project and get the Assembly-CSharp.dll that it has compiled from the Library/ScriptAssemblies folder
2) Create a new project, and place the dll in the Assets folder and rename it.
Note:Not renaming it causes the following error - I'm assuming the name is reserved
ApplicationException: Unable to find a suitable compiler UnityEditor.Scripting.ScriptCompilers.CreateCompilerInstance (MonoIsland island, Boolean buildingForEditor, BuildTarget targetPlatform) (at C:/BuildAgent/work/812c4f5049264fad/Editor/Mono/Scripting/ScriptCompilers.cs:99)
This works and satisfies the requirement of having one dll that i could distribute.
The problem I have occurs when I add new scripts that try to subclass a class that is wrapped in the dll.
So for instance if the dll packages a class such as
namespace MyNameSpace {
public class Fruit: IFruit {
}
..
..
}
and I create a new script called Banana that attempts to subclass Fruit
namespace MyNameSpace
{
public class Banana : Fruit, IFruit {
}
..
..
}
This causes a runtime exception TypeLoadException: Could not load type 'MyNameSpace.Banana' from assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
I haven't so far been able to find out why this is. Is it related to changing the name of the dll? Or is there something fundamental about the Assembly-CSharp.dll that i took from the original project that mean it can't be used in this way? As I say I don't have a background in .NET, so I realise what I'm doing maybe somewhat naiive.
Also, I have experimented with compiling individual scripts, and groups of scripts, into dlls, and extending classes embedded i those dlls without any problems. I've used Assembly Builder ( http://studio.foriero.com/products/assembly-builder/assembly-builder.php ) to do this and it works fine for compiling a limited number of scripts (which it is what it's built for). It seems to have problems with large numbers of classes. So if I try to build my entire project like that it will crash. I could also look at compiling the project into a number of dlls, however I have some significant refactoring I'd have to do, and this is time sensitive.
I'm also open to suggestions of completely different ways of doing this, it may even be that I'm missing something really obvious?
Anyway, I appreciate any help I can get!
However it's a requirement that the code content of the main project itself, preferably including the class they need to subclass, is not accessible to the devs.
Wat? Are you hiring shady people, or working for a pointy-haired boss..? Either way, sounds like you've got a rather dysfunctional company structure, addressing which would be my first suggestion as to "completely different ways of doing things. "
Um... so you want dev's to subclass, without the class they are subclassing????
Also, format your code
Answer by wkrp · Jul 09, 2013 at 07:42 AM
All sorted using Visual Studio to create a separate project. Compile the scripts into a dll and then used the dll in the project I want to distribute.