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)
- Host: GitHub
- URL: https://github.com/sharp0802/dhost
- Owner: Sharp0802
- Created: 2024-03-28T11:24:06.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-29T02:37:12.000Z (about 2 years ago)
- Last Synced: 2025-01-25T22:34:02.663Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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;
}
```