_ /( )( __ \ ( ___ ) ) ( |
( ) | ( \ ) | ( ) | _ | ) | (_) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
) | _ | |||||||||||||||||
(___) | (__/ ) | (___) | (_) |
)_( (_)(__/ (_)
1) Add the following class to your project:
internal static class ModuleInitializer { internal static void Run() { // TODO: Add assembly initialization logic. } }
2) 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