Project Description
Analyze existing DLL and generate C# source code for stub DLL containing the same public API but no implementation.

This project was originally developed by Mainsoft, which has generously decided to contribute this work to the public.

I believe that the stub generator utility will usually be used in very specific phases of development cycle, which means that this utility does not get every-day usage and therefore doesn't have a great U/I and is not tested on a large variaty of DLLs. As a result the process is semi-automatic (see usage instructiosn below) and you may want to fix a bug or two. Please submit your fixes and help the community.

I belive that the utility has many varied usages and I am interested in feedback from the community regarding different usage scenarios.
Mainsoft used the stub generator for disabling specific features of the product in different scenarios by replacing implementation DLLs with stub DLLs. This methodology dramatically reduced the number of #if's in the code.
Another possible usage scenario may be when licensing issues occur (in-ability to re-distribute dependencies in specific cases).

Legal warning: I am not a lawyer and I do not know the implications of executing this utility on a library you did not develop. Absolutly no legal warranty is provided with this regard. Generating stubs is done solely at your own risk.

There is no fancy user interface. Just modify the main a bit. It should contain:

AssemblyConverter x = new AssemblyConverter (string pathToDll, string outputSourceDir, string [] dontmodify, string [] usingNamespace);
x.doWork ();

pathToDll - the path to the DLL for which you want to generate stubs
outputSourceDir - Where the generated source files will reside
dontmodify - list of source files that should not be modified if they exist (initially an empty list).
usingNamespace - the list of namespaces for which 'using' directives should appear in each source file

The process of generating stubs is semi-automatic and somewhat iterative. After the first execution, the stubs may not build (e.g. due to a bug in the stub generator). At this point you can either add another using directive, fix the bug in the stub generator, or just modify the generated code. Fixing the bug is preferrable when the compilation error occurs in many files. Modifying the code is better when there are few compilation errors.
However, after modifying the code, re-running the stub generator will overwrite the code changes and you will end up having to perform the code modifications many times. Hence the 'dontmodify' input which allows you to tell the stub generator not to change these files (if they exist). Every time you modify a generated file, just add its name to the dontmodify list.

Licensing: The license of this project is MS-PL. However note that this project depends on CECIL project. The source code of the StubGenerator includes a binary of Cecil.dll, and you are obviously bound by the license of CECIL as well (currently MIT X11 license).

Last edited Jun 15, 2008 at 1:59 PM by noaml, version 3