BetterStartupHook 1.0.0

dotnet add package BetterStartupHook --version 1.0.0
NuGet\Install-Package BetterStartupHook -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BetterStartupHook" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BetterStartupHook --version 1.0.0
#r "nuget: BetterStartupHook, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BetterStartupHook as a Cake Addin
#addin nuget:?package=BetterStartupHook&version=1.0.0

// Install BetterStartupHook as a Cake Tool
#tool nuget:?package=BetterStartupHook&version=1.0.0

Better Startup Hooks for .NET

The low-level api for startup hooks does not include dependency resolution for non-app assemblies. In other words hooks, dependencies to other assemblies than included in the injected application need extra dependency resolution logic.

Better-Startup-Hook allows to create startup hooks that automatically resolves additional dependencies.

How-does it work?

The project consists of a startup hook in BetterStartupHook.dll, whichs loads the actual logic to inject into the application from other assemblies and does all the extra logic to resolve the dependencies.

The BETTER_STARTUP_HOOKS environment variable can be used to specify a list of additional managed assemblies that contain a BetterStartupHook type with a public static void Initialize() method, each of which will be called in the order specified, before the Main entry point.

using System;

internal class BetterStartupHook
{
    public static void Initialize()
    {
       //Your custom logic.. 
    }
}

How-To create/use a BetterStartupHook

1. Implement your hook by creating a .Net class library project e.g.
using OpenTelemetry;
using OpenTelemetry.Trace;
using System;

internal class BetterStartupHook
{
    public static void Initialize()
    {
        //Your custom logic goes here...
        Console.WriteLiine("Hello World");
    }
}
2. Extend your .csproj to copy nuget references into your output folder

Add CopyLocalLockFileAssemblies as shown in the following

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

    ...
</Project>

Read more about CopyLocalLockFileAssemblies property

3. Register your better-startup-hook assembly

Windows:

BETTER_STARTUP_HOOKS="<path-to-betterstartuphook>\\MyStartupHook.dll

Linux:

BETTER_STARTUP_HOOKS="<path-to-betterstartuphook>\\MyStartupHook.dll

4. Register the BetterStartupHook assembly as your applications startup hook.

Windows:

DOTNET_STARTUP_HOOKS="<path-to-betterstartuphook>\\BetterStartupHook.dll

Linux:

DOTNET_STARTUP_HOOKS="<path-to-betterstartuphook>/BetterStartupHook.dll

Contribute

This is an open source project, and we gladly accept new contributions and contributors.

License

Licensed under Apache 2.0 license. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 88 3/20/2024

First release