This Is Not Open Source(TM)

time to read 10 min | 1937 words

No, it is not a rant against some non OSS tool.

When I was at DevTeach, I talked with a few people that mentioned that their compnay has an... aversion to OSS and they wanted a way around that. Beind technical minded and a "rules, what rules?" types of guy, I suggested that they would take an OSS project (assuming the license allows it), and just rename the namespaces.

This is a possible approach, but it may be too much work in many cases. I suggested post compile weaving, and people looked at me as if I have grown two heads ( I didn't, I checked ). I just now remember this conversation, and wrote this little script with Boo and Mono.Cecil, which would take an existing assembly and rename everything from an old value to a new one.


booi Castle.ActiveRecord.dll Castle Tower

Now enjoy your Tower.ActiveRecord.dll :-)

import Mono.Cecil

import System.IO


if argv.Length != 3:

       print "Usage: booi <dll/exe file> <OldNameSpace> <NewNameSpace>"



if not File.Exists(argv[0]):

       print argv[0] +" does not exists!"



filename = argv[0]

oldNamespace = argv[1]

newNamespace = argv[2]


myLibrary = AssemblyFactory.GetAssembly (filename);

myLibrary.Name.Name = myLibrary.Name.Name.Replace(oldNamespace , newNamespace )


for module as ModuleDefinition in myLibrary.Modules:

       module.Name = module.Name.Replace(oldNamespace , newNamespace )

       for type as TypeDefinition in module.Types:

              type.Namespace = type.Namespace.Replace(oldNamespace , newNamespace )


AssemblyFactory.SaveAssembly(myLibrary, Path.GetFileName(filename.Replace(oldNamespace , newNamespace ) ) )

Oh, and written in notepad on the command line while I waited for #Develop to be installed on a new machine.