Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
netcorehost
A Rust library for hosting .NET Core applications.
This crate allows a .NET Core app to be run inside the current process or to load it and call a contained method directly.
Basic Usage
The first step is to load the hostfxr library with handles the hosting. This can be done with [nethost::load_hostfxr()
]
which automatically locates the library on your system. The returned instance of Hostfxr
can then be used to initialize
a new HostfxrContext
through one of the initialize_*
methods like initialize_for_dotnet_command_line
which in turn be used to run the app associated with the context or to load a pointer to a function od the loaded library.
Examples
Running an application
Assuming the following app located inside the current folder and named Test.dll
:
public static
The following code will setup the hostfxr library, load the app and run its Main
method.
let assembly_path = from_str?;
let hostfxr = load_hostfxr?;
let context = hostfxr.initialize_for_dotnet_command_line?;
let result = context.run_app;
Calling a managed function
Assuming the following app located inside the current folder and named Test.dll
:
The following code will setup the hostfxr library, load the app and call the Hello
method.
The method has the default signature which avoids having to specify it. It accepts a ptr to some data and the size of said data.
let hostfxr = load_hostfxr?;
let context =
hostfxr.initialize_for_runtime_config?;
let fn_loader =
context.get_delegate_loader_for_assembly?;
let hello = fn_loader.get_function_pointer_with_default_signature;
let result = unsafe ;
Alternatively it is possible to call a method with any signature if it is annotated with UnmanagedCallersOnly
(loaded with
get_function_pointer_for_unmanaged_callers_only_method
) or if the signature is passed to get_function_pointer
.
License
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)