ometimes when working with C# you discover some hidden gems. Some of them very useful, other ones a little bit harder to find a good way to benefit from their functionality. One of those hidden gems that I discovered some days ago are Startup Hooks
A Startup Hook is a class named StartupHook that has a public method static void Initialize().
Important: Don’t put this class in a namespace.
To execute this Startup Hook before any other code in your application, you need to set the DOTNET_STARTUP_HOOKS environment variable. You can specify a list of managed assemblies that each contain a Startup Hook class like above. You can specify the assembly name either through the simple name (e.g. example) or through the full path (e.g. .d:\example.dll)
Here is the output when I run this application: