InjectModuleInitializer icon indicating copy to clipboard operation
InjectModuleInitializer copied to clipboard

Console program and nuget package to inject a module initializer method into a built .NET assembly



__ /( ___ )( __ \ ( ___ )
) ( | ( ) || ( \ )| ( ) | _ | | | | | || | ) || | | |() | | | | | || | | || | | |
| | | | | || | ) || | | | _ | | | (
) || (/ )| () |() )( ()(/ (_______)

  1. Add the following class to your project:

internal static class ModuleInitializer { internal static void Run() { // TODO: Add assembly initialization logic. } }

  1. Add initialization logic to the Run method's body.



( ___ )( ___ \ ( ___ )|\ /|__ / | ( ) || ( ) )| ( ) || ) ( | ) (
| (
) || (/ / | | | || | | | | |
| ___ || __ ( | | | || | | | | |
| ( ) || ( \ \ | | | || | | | | |
| ) ( || )
) )| () || () | | |
|/ ||/ _
/ ()() )_(

The InjectModuleInitializer nuget package modifies your project file, adding an "AfterBuild" target. The target is configured such that, upon a successful build of your project, it runs the InjectModuleInitializer.exe program. This program modifies your compiled assembly so that, when it is loaded for the first time, ModuleInitializer.Run() is called.




( \ __ /( ____ ( ____ ( ( /|( ____ ( ____
| ( ) ( | ( /| ( /| \ ( || ( /| ( / | | | | | | | (
| \ | || (_____ | (__
| | | | | | | ) | (\ ) |(___ )| )
| | | | | | | ( | | \ | ) || (
| (____/_
) (| (/| (/| ) \ |/_) || (/
(
/_/(/(/|/ ))_)(___/

InjectModuleInitializer

Command line program to inject a module initializer into a .NET assembly.

Copyright (C) 2009-2012 Einar Egilsson http://einaregilsson.com/module-initializers-in-csharp/

This program is licensed under the MIT license: http://opensource.org/licenses/MIT


ASCII art courtesy of patorjk.com/software/taag/#p=display&f=Epic&t=patorjk.com