Welcome Guest, you are in: Login

dbones docs


Navigation (boxes)

Search the wiki

This article will take you though the steps to using Boxes.Core in a simple application. Consider this the HELLO WORLD app


The output of this will be a small console application which has a sub folder called packages.

If the folder is empty it will display a message informing the user there are no packages.

If we copy packages into the folder, the program will list each package and any Assembly which is exported by that package.

Create the main app

The first thing is to create a console application (.NET 4+). We shall call the project Boxes.SimpleApp.CommandLine.

Once this has been created, we will need to add Boxes.Core to the project. open Nuget and install Boxes.Core


Once we have added Boxes to the project, we can add the following code in the Program.Main

static void Main(string[] args)
    //in this compiled application we want to 
    //have a sub folder for our packages the following
    //will ensure it has been created
    var location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    string packagesDirectory = Path.Combine(location, "Packages");
    if (!Directory.Exists(packagesDirectory))

    PackageRegistry registry = new PackageRegistry();
    using (var loader = new DefaultLoader(registry))
        //discover any packages
        registry.DiscoverPackages(new PackageScanner(packagesDirectory));
        if(!registry.Packages.Any(x=> x.CanLoad))
            Console.WriteLine("No packages could be loaded. please write some and add them to the\n{0} directory", packagesDirectory);

        //load the packages into the app ready to use
        foreach (var package in registry.Packages)
            Console.WriteLine("Package: {0}\nExported Assemblies", package.Name);
            foreach (var loadedAssembly in package.LoadedAssemblies)
                Console.WriteLine("\t{0}", loadedAssembly.GetName().Name);



What does the code do?
the above code does
  • Checks to see if the application has a subfolder called packages, if not it creates it.
  • Initialises Boxes by creating a PackageRegistry and a DefaultLoader
  • Scans the Package sub directory for any packages
  • If no packages are found it informs the user
  • else it lists the packages

Compile and run the application to ensure it works (do not forget to add any missing namespaces.) It should say there are no packages.

Once the application runs, you can look in the bin directory. There you will see the DLL's for the project and a sub folder called packages.

Create a package

To keep things simple, our package will be associated directly with a .NET project. This means the project's output is a Package.

In the same solution add a Library project (.NET 4+), you can call it MyFirstPackage

By minimum a package requires a manifest (the default is XML). This provides important meta data for Boxes to understand how to handle the package.

In the MyFirstPackage project add a file called manifest.xml and copy in the following (link to enable intellisense on the manifest):

<?xml version="1.0" encoding="utf-8" ?> 
<manifest xmlns="http://schemas.dbones.co.uk/developer/boxes/2012">
  <description>this is my first package</description>
    <assembly name="MyFirstPackage"/>

We are not done, as the compiled output at the moment will not include the manifest in the output. To enable this

  • Right click the manifest.xml
  • Click on properties
  • Set to Copy Always


For this example we are ready, normally we would add some excellent code. Build the project and check to see if we have at least the

  • MyFisrtPackage.dll
  • manifest.xml

In the bin directory (most likely there will be a pdb file)

Wrapping it up

At this point we should have 2 built projects (the console app and code library), we need to add the package into the Packages folder.

Create a Directory in the Packages folder called MyFirstPackage and copy the output files from the MyFirstPackage (dll and manifest), it should look like the following:


That's it, you can now run the console app again, and it will output the packages.



This simple application has briefly introduced to:

  • Creation of a package (where the .NET project is a package)
  • The manifest file
  • Discovery of any available packages
  • Loading of all packages into the current AppDomain using the DefaultLoader (note there is another loader)
  • A quick glance into the Boxes API

The key part is we now have everything we need in order to use our packages inside the AppDomain

  Name Size
- simpleApp-CopiedPackage.png 42.07 KB
- SimpleApp-output.png 16.83 KB
dbones docs, is a sub-site of dbones.co.uk, all its content belongs to dbones.co.uk, this also includes logo's.