An open API service indexing awesome lists of open source software.

https://github.com/sharp0802/dhost

A simple CoreCLR hosting library (.NET 5 or later)
https://github.com/sharp0802/dhost

Last synced: 21 days ago
JSON representation

A simple CoreCLR hosting library (.NET 5 or later)

Awesome Lists containing this project

README

          

# DHost

> [!WARNING]
> Currently, Only .NET 5.0 or higher is supported.

A simple .NET native-host wrapper for C++

## How to build

### Summary

```shell
$ mkdir build
$ cd build
$ cmake -DNETHOST_RUNTIME_IDENTIFIER="linux-x64" -DNETHOST_RUNTIME_VERSION="8.0.3" ../
$ make # use what you configured with cmake
```

### CMake Variables

> [!WARNING]
> Target platform not altered even if mismatched with `NETHOST_RUNTIME_IDENTIFIER`.
> To change target platform, Use cross-platform tools such as MINGW.

- `NETHOST_RUNTIME_IDENTIFIER` : .NET RID (See [Catalog](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog))
- `NETHOST_RUNTIME_VERSION` : .NET Runtime Version (See [Version List](https://www.nuget.org/packages/runtime.linux-x64.Microsoft.NETCore.DotNetAppHost#versions-body-tab))

## How to use (Sample)

- clr.csproj

```xml


Exe
net8.0
enable
enable

```

- Program.cs

```c#
internal static class Program
{
public static void Entry()
{
Console.WriteLine($"Hello from '{typeof(Program).AssemblyQualifiedName}'");
}

public static void Main()
{
// dummy
}
}
```

- main.cpp

> [!IMPORTANT]
> When specifying type, Assembly qualified name is required.

```c++
#include "library.h"

int main()
{
DHost ctx("clr.runtimeconfig.json");

if (!ctx.LoadAssembly("clr.dll"))
{
puts("asm");
return -1;
}

const auto main = reinterpret_cast(ctx.LoadMethod(
"Program, clr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"Entry",
"System.Action, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"));
if (!main)
{
puts("fptr");
return -1;
}

main();

return 0;
}
```