David Merriman
David Merriman

Reputation: 6086

Is there a way to force MonoDevelop to build/load an assembly?

I have a MonoTouch application which is managing a list of assemblies. I want developers to be able to modify that list of assemblies as easily as possible. I was hoping that I could just have them add an assembly to the application's references, and that I could then loop through them like this:

foreach (AssemblyName assemblyName in this.GetType().GetReferencedAssemblies())
{
    Assembly assembly = Assembly.Load(assemblyName);
    //Do something with assembly
}

The problem that I'm having is that all assemblies I am not explicitly referencing are not found in the array returned by GetReferencedAssemblies(), and the application compiles with a warning Library 'Unreferenced.dll' missing in app bundle, cannot extract content.

Is there a way to force MonoDevelop or MonoTouch (not sure which is responsible here) to build and load all assemblies in the References folder without an explicit reference to some type in those assemblies?

Upvotes: 1

Views: 674

Answers (1)

poupou
poupou

Reputation: 43553

It starts with a compiler feature. In order to get in the GetReferencedAssemblies list the assembly must be referenced. It can be directly (e.g. an explicit type is referenced) or indirectly (e.g. a reference's references). If the compiler does not see a reference to an assembly then it won't be part of the AssemblyRef metadata.

Afterward the lack of references means the managed linker (first, optional) and then the AOT compiler (second, mandatory for devices) won't process and compile the assemblies.

The easy way is to ensure a reference to a type in each assembly exists in your application. It's one line of code by assembly - but it's easy to forget too.

You can automate this by adding a pre-build step (in MonoDevelop) that will read the assemblies (e.g. in a directory) and generated a C# file (e.g. a partial class) that you include in your application. That way people won't have to remember to add new assemblies to your build.

Upvotes: 1

Related Questions