DllMain 1.0.2
dotnet add package DllMain --version 1.0.2
NuGet\Install-Package DllMain -Version 1.0.2
<PackageReference Include="DllMain" Version="1.0.2" />
<PackageVersion Include="DllMain" Version="1.0.2" />
<PackageReference Include="DllMain" />
paket add DllMain --version 1.0.2
#r "nuget: DllMain, 1.0.2"
#:package DllMain@1.0.2
#addin nuget:?package=DllMain&version=1.0.2
#tool nuget:?package=DllMain&version=1.0.2
DllMain
This appropriately named package allows you to safely define a DllMain
function for your NativeAOT library in C.
Getting started
Add the DllMain NuGet package to your project, then follow the instructions from readme.txt.
How this works
The NativeAOT toolchain declares multiple MSBuild targets to build/link the NativeAOT library. Among other things, it injects an object file that defines an empty DllMain
function, in an effort to avoid user-defined DllMain
.NET implementations, since the NativeAOT runtime doesn't support initialization under DllMain
's loader lock.
This package declares another target that gets injected between SetupOSSpecificProps (which builds LinkerArg
) and LinkNative (which calls the linker with those arguments). This target:
- Builds the user-defined
.c
file, - Removes the toolchain-defined object file with an empty
DllMain
from linker arguments, - Adds compiled user-defined C code to linker arguments.
- Forces the linker to include the otherwise unreferenced new
DllMain
function in the final library.
As long as the user doesn't call managed code from their DllMain
function, the resulting library should not break any rules imposed by the OS or the NativeAOT runtime/toolchain.
Learn more about Target Frameworks and .NET Standard.
This package has 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.