diff --git a/core/hosting/HostWithCoreClrHost/README.md b/core/hosting/HostWithCoreClrHost/README.md deleted file mode 100644 index f3505162224..00000000000 --- a/core/hosting/HostWithCoreClrHost/README.md +++ /dev/null @@ -1,20 +0,0 @@ -.NET Core Hosting Sample -======================== - -This sample demonstrates a simple .NET Core host using the hosting APIs from [`coreclrhost.h`](https://github.com/dotnet/coreclr/blob/main/src/coreclr/hosts/inc/coreclrhost.h). The sample host loads and starts the .NET runtime, loads managed code, calls into a managed method, and provides a function pointer for the managed code to call back into the host. - -This sample is part of the [.NET Core hosting tutorial](https://docs.microsoft.com/dotnet/core/tutorials/netcore-hosting). See that topic for a more detailed explanation of this sample. - -About .NET Core Hosts ---------------------- - -.NET Core applications are always run by a host. In most cases, the default dotnet.exe host is used. - -It is possible to create your own host, though, to enable starting and running .NET Core code from a native application, or to enable a high degree of control over how the runtime operates. More complex, real-world hosts can be found in the [dotnet/coreclr](https://github.com/dotnet/coreclr/tree/master/src/coreclr/hosts) repository. - -Build and Run -------------- - -To build this sample, just use the included build scripts *build.bat*, *build.sh*, or *buildOsx.sh*. These scripts build both the managed target assembly (ManagedLibrary.dll) and the host (SampleHost.exe). The build scripts are just simple wrappers around two build calls (`dotnet publish` for the managed component of the sample and cl.exe/g++ for the host), so it's also easy to build the two components directly if you prefer. The build scripts build for Windows 10 (x64), Linux (x64), and OSX (x64), respectively, and assume that both the dotnet CLI and the C++ compiler (cl.exe or g++) are available on the path. On Windows, a [Developer Command Prompt for Visual Studio](https://docs.microsoft.com/cpp/build/building-on-the-command-line#developer_command_prompt_shortcuts) should be used. The build scripts will need modified if you intend to target other platforms or use tools from other paths. Be sure that the bitness of the host and sample app match. By default, the build scripts build ManagedLibrary.dll for x64, so you will need to build the host for 64-bit. - -To run the host, just execute SampleHost from the bin/{{OS}} directory. diff --git a/core/hosting/HostWithCoreClrHost/build.bat b/core/hosting/HostWithCoreClrHost/build.bat deleted file mode 100644 index adf7f5e056b..00000000000 --- a/core/hosting/HostWithCoreClrHost/build.bat +++ /dev/null @@ -1,17 +0,0 @@ -@echo off - -REM This script builds the sample for x64 Windows 10. If using Win7, adjust the 'dotnet publish' command. -REM It assumes that both the dotnet CLI and cl.exe compiler are available on the path. -REM A Visual Studio Developer Command Prompt will already have cl.exe on its path. - -SET SRCDIR=%~dp0src -SET OUTDIR=%~dp0bin\windows - -mkdir %OUTDIR% - -REM Build managed component -echo Building Managed Library -dotnet publish --self-contained -r win10-x64 %SRCDIR%\ManagedLibrary\ManagedLibrary.csproj -o %OUTDIR% - -REM Build native component -cl.exe %SRCDIR%\SampleHost.cpp /Fo%OUTDIR%\ /Fd%OUTDIR%\SampleHost.pdb /EHsc /Od /GS /sdl /Zi /D "WINDOWS" /link ole32.lib /out:%OUTDIR%\SampleHost.exe diff --git a/core/hosting/HostWithCoreClrHost/build.sh b/core/hosting/HostWithCoreClrHost/build.sh deleted file mode 100644 index d3c0042d626..00000000000 --- a/core/hosting/HostWithCoreClrHost/build.sh +++ /dev/null @@ -1,19 +0,0 @@ -# This script builds the sample for x64 Linux. -# It assumes that both the dotnet CLI and g++ compiler are available on the path. - -SCRIPTPATH=$(readlink -f "$0") -BASEDIR=$(dirname $SCRIPTPATH) -SRCDIR=${BASEDIR}/src -OUTDIR=${BASEDIR}/bin/linux - -# Make output directory, if needed -if [ ! -d "${OUTDIR}" ]; then - mkdir -p ${OUTDIR} -fi - -# Build managed component -echo Building Managed Library -dotnet publish --self-contained -r linux-x64 ${SRCDIR}/ManagedLibrary/ManagedLibrary.csproj -o ${OUTDIR} - -# Build native component -g++ -o ${OUTDIR}/SampleHost -D LINUX ${SRCDIR}/SampleHost.cpp -ldl diff --git a/core/hosting/HostWithCoreClrHost/buildOsx.sh b/core/hosting/HostWithCoreClrHost/buildOsx.sh deleted file mode 100755 index 5f15c1ff004..00000000000 --- a/core/hosting/HostWithCoreClrHost/buildOsx.sh +++ /dev/null @@ -1,20 +0,0 @@ -# This script builds the sample for x64 OSX. -# It assumes that both the dotnet CLI and g++ compiler are available on the path. - -BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -SRCDIR=${BASEDIR}/src -OUTDIR=${BASEDIR}/bin/osx - -# Make output directory, if needed -if [ ! -d "${OUTDIR}" ]; then - mkdir -p ${OUTDIR} -fi - -# Build managed component -echo Building Managed Library -echo dotnet publish --self-contained -r osx-x64 ${SRCDIR}/ManagedLibrary/ManagedLibrary.csproj -o ${OUTDIR} -dotnet publish --self-contained -r osx-x64 ${SRCDIR}/ManagedLibrary/ManagedLibrary.csproj -o ${OUTDIR} - -# Build native component -# -D both LINUX and OSX since most LINUX code paths apply to OSX also -g++ -o ${OUTDIR}/SampleHost -D LINUX -D OSX ${SRCDIR}/SampleHost.cpp -ldl diff --git a/core/hosting/HostWithCoreClrHost/src/ManagedLibrary/ManagedLibrary.csproj b/core/hosting/HostWithCoreClrHost/src/ManagedLibrary/ManagedLibrary.csproj deleted file mode 100644 index 96bc51e4adf..00000000000 --- a/core/hosting/HostWithCoreClrHost/src/ManagedLibrary/ManagedLibrary.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - - Exe - netcoreapp2.1 - - - diff --git a/core/hosting/HostWithCoreClrHost/src/ManagedLibrary/ManagedWorker.cs b/core/hosting/HostWithCoreClrHost/src/ManagedLibrary/ManagedWorker.cs deleted file mode 100644 index c7f6b69c8b6..00000000000 --- a/core/hosting/HostWithCoreClrHost/src/ManagedLibrary/ManagedWorker.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading; - -namespace ManagedLibrary -{ - // Sample managed code for the host to call - public class ManagedWorker - { - // This assembly is being built as an exe as a simple way to - // get .NET Core runtime libraries deployed (`dotnet publish` will - // publish .NET Core libraries for exes). Therefore, this assembly - // requires an entry point method even though it is unused. - public static void Main() - { - Console.WriteLine("This assembly is not meant to be run directly."); - Console.WriteLine("Instead, please use the SampleHost process to load this assembly."); - } - - public delegate int ReportProgressFunction(int progress); - - // This test method doesn't actually do anything, it just takes some input parameters, - // waits (in a loop) for a bit, invoking the callback function periodically, and - // then returns a string version of the double[] passed in. - [return: MarshalAs(UnmanagedType.LPStr)] - public static string DoWork( - [MarshalAs(UnmanagedType.LPStr)] string jobName, - int iterations, - int dataSize, - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] double[] data, - ReportProgressFunction reportProgressFunction) - { - for (int i = 1; i <= iterations; i++) - { - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine($"Beginning work iteration {i}"); - Console.ResetColor(); - - // Pause as if doing work - Thread.Sleep(1000); - - // Call the native callback and write its return value to the console - var progressResponse = reportProgressFunction(i); - Console.WriteLine($"Received response [{progressResponse}] from progress function"); - } - - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"Work completed"); - Console.ResetColor(); - - return $"Data received: {string.Join(", ", data.Select(d => d.ToString()))}"; - } - } -} diff --git a/core/hosting/HostWithCoreClrHost/src/SampleHost.cpp b/core/hosting/HostWithCoreClrHost/src/SampleHost.cpp deleted file mode 100644 index d39988028e0..00000000000 --- a/core/hosting/HostWithCoreClrHost/src/SampleHost.cpp +++ /dev/null @@ -1,329 +0,0 @@ -#include -#include -#include -#include - -// https://github.com/dotnet/coreclr/blob/master/src/coreclr/hosts/inc/coreclrhost.h -#include "coreclrhost.h" - -#define MANAGED_ASSEMBLY "ManagedLibrary.dll" - -// Define OS-specific items like the CoreCLR library's name and path elements -#if WINDOWS -#include -#define FS_SEPARATOR "\\" -#define PATH_DELIMITER ";" -#define CORECLR_FILE_NAME "coreclr.dll" -#elif LINUX -#include -#include -#include -#define FS_SEPARATOR "/" -#define PATH_DELIMITER ":" -#define MAX_PATH PATH_MAX - #if OSX - // For OSX, use Linux defines except that the CoreCLR runtime - // library has a different name - #define CORECLR_FILE_NAME "libcoreclr.dylib" - #else - #define CORECLR_FILE_NAME "libcoreclr.so" - #endif -#endif - -// Function pointer types for the managed call and callback -typedef int (*report_callback_ptr)(int progress); -typedef char* (*doWork_ptr)(const char* jobName, int iterations, int dataSize, double* data, report_callback_ptr callbackFunction); - -void BuildTpaList(const char* directory, const char* extension, std::string& tpaList); -int ReportProgressCallback(int progress); - -int main(int argc, char* argv[]) -{ - // Get the current executable's directory - // This sample assumes that both CoreCLR and the - // managed assembly to be loaded are next to this host - // so we need to get the current path in order to locate those. - char runtimePath[MAX_PATH]; -#if WINDOWS - GetFullPathNameA(argv[0], MAX_PATH, runtimePath, NULL); -#elif LINUX - realpath(argv[0], runtimePath); -#endif - char *last_slash = strrchr(runtimePath, FS_SEPARATOR[0]); - if (last_slash != NULL) - *last_slash = 0; - - // Construct the CoreCLR path - // For this sample, we know CoreCLR's path. For other hosts, - // it may be necessary to probe for coreclr.dll/libcoreclr.so - std::string coreClrPath(runtimePath); - coreClrPath.append(FS_SEPARATOR); - coreClrPath.append(CORECLR_FILE_NAME); - - // Construct the managed library path - std::string managedLibraryPath(runtimePath); - managedLibraryPath.append(FS_SEPARATOR); - managedLibraryPath.append(MANAGED_ASSEMBLY); - - // - // STEP 1: Load CoreCLR (coreclr.dll/libcoreclr.so) - // -#if WINDOWS - // - HMODULE coreClr = LoadLibraryExA(coreClrPath.c_str(), NULL, 0); - // -#elif LINUX - void *coreClr = dlopen(coreClrPath.c_str(), RTLD_NOW | RTLD_LOCAL); -#endif - if (coreClr == NULL) - { - printf("ERROR: Failed to load CoreCLR from %s\n", coreClrPath.c_str()); - return -1; - } - else - { - printf("Loaded CoreCLR from %s\n", coreClrPath.c_str()); - } - - // - // STEP 2: Get CoreCLR hosting functions - // -#if WINDOWS - // - coreclr_initialize_ptr initializeCoreClr = (coreclr_initialize_ptr)GetProcAddress(coreClr, "coreclr_initialize"); - coreclr_create_delegate_ptr createManagedDelegate = (coreclr_create_delegate_ptr)GetProcAddress(coreClr, "coreclr_create_delegate"); - coreclr_shutdown_ptr shutdownCoreClr = (coreclr_shutdown_ptr)GetProcAddress(coreClr, "coreclr_shutdown"); - // -#elif LINUX - coreclr_initialize_ptr initializeCoreClr = (coreclr_initialize_ptr)dlsym(coreClr, "coreclr_initialize"); - coreclr_create_delegate_ptr createManagedDelegate = (coreclr_create_delegate_ptr)dlsym(coreClr, "coreclr_create_delegate"); - coreclr_shutdown_ptr shutdownCoreClr = (coreclr_shutdown_ptr)dlsym(coreClr, "coreclr_shutdown"); -#endif - - if (initializeCoreClr == NULL) - { - printf("coreclr_initialize not found"); - return -1; - } - - if (createManagedDelegate == NULL) - { - printf("coreclr_create_delegate not found"); - return -1; - } - - if (shutdownCoreClr == NULL) - { - printf("coreclr_shutdown not found"); - return -1; - } - - // - // STEP 3: Construct properties used when starting the runtime - // - - // Construct the trusted platform assemblies (TPA) list - // This is the list of assemblies that .NET Core can load as - // trusted system assemblies. - // For this host (as with most), assemblies next to CoreCLR will - // be included in the TPA list - std::string tpaList; - BuildTpaList(runtimePath, ".dll", tpaList); - - // - // Define CoreCLR properties - // Other properties related to assembly loading are common here, - // but for this simple sample, TRUSTED_PLATFORM_ASSEMBLIES is all - // that is needed. Check hosting documentation for other common properties. - const char* propertyKeys[] = { - "TRUSTED_PLATFORM_ASSEMBLIES" // Trusted assemblies - }; - - const char* propertyValues[] = { - tpaList.c_str() - }; - // - - // - // STEP 4: Start the CoreCLR runtime - // - - // - void* hostHandle; - unsigned int domainId; - - // This function both starts the .NET Core runtime and creates - // the default (and only) AppDomain - int hr = initializeCoreClr( - runtimePath, // App base path - "SampleHost", // AppDomain friendly name - sizeof(propertyKeys) / sizeof(char*), // Property count - propertyKeys, // Property names - propertyValues, // Property values - &hostHandle, // Host handle - &domainId); // AppDomain ID - // - - if (hr >= 0) - { - printf("CoreCLR started\n"); - } - else - { - printf("coreclr_initialize failed - status: 0x%08x\n", hr); - return -1; - } - - // - // STEP 5: Create delegate to managed code and invoke it - // - - // - doWork_ptr managedDelegate; - - // The assembly name passed in the third parameter is a managed assembly name - // as described at https://docs.microsoft.com/dotnet/framework/app-domains/assembly-names - hr = createManagedDelegate( - hostHandle, - domainId, - "ManagedLibrary, Version=1.0.0.0", - "ManagedLibrary.ManagedWorker", - "DoWork", - (void**)&managedDelegate); - // - - if (hr >= 0) - { - printf("Managed delegate created\n"); - } - else - { - printf("coreclr_create_delegate failed - status: 0x%08x\n", hr); - return -1; - } - - // Create sample data for the double[] argument of the managed method to be called - double data[4]; - data[0] = 0; - data[1] = 0.25; - data[2] = 0.5; - data[3] = 0.75; - - // Invoke the managed delegate and write the returned string to the console - char* ret = managedDelegate("Test job", 5, sizeof(data) / sizeof(double), data, ReportProgressCallback); - - printf("Managed code returned: %s\n", ret); - - // Strings returned to native code must be freed by the native code -#if WINDOWS - CoTaskMemFree(ret); -#elif LINUX - free(ret); -#endif - - // - // STEP 6: Shutdown CoreCLR - // - - // - hr = shutdownCoreClr(hostHandle, domainId); - // - - if (hr >= 0) - { - printf("CoreCLR successfully shutdown\n"); - } - else - { - printf("coreclr_shutdown failed - status: 0x%08x\n", hr); - } - - return 0; -} - -#if WINDOWS -// Win32 directory search for .dll files -// -void BuildTpaList(const char* directory, const char* extension, std::string& tpaList) -{ - // This will add all files with a .dll extension to the TPA list. - // This will include unmanaged assemblies (coreclr.dll, for example) that don't - // belong on the TPA list. In a real host, only managed assemblies that the host - // expects to load should be included. Having extra unmanaged assemblies doesn't - // cause anything to fail, though, so this function just enumerates all dll's in - // order to keep this sample concise. - std::string searchPath(directory); - searchPath.append(FS_SEPARATOR); - searchPath.append("*"); - searchPath.append(extension); - - WIN32_FIND_DATAA findData; - HANDLE fileHandle = FindFirstFileA(searchPath.c_str(), &findData); - - if (fileHandle != INVALID_HANDLE_VALUE) - { - do - { - // Append the assembly to the list - tpaList.append(directory); - tpaList.append(FS_SEPARATOR); - tpaList.append(findData.cFileName); - tpaList.append(PATH_DELIMITER); - - // Note that the CLR does not guarantee which assembly will be loaded if an assembly - // is in the TPA list multiple times (perhaps from different paths or perhaps with different NI/NI.dll - // extensions. Therefore, a real host should probably add items to the list in priority order and only - // add a file if it's not already present on the list. - // - // For this simple sample, though, and because we're only loading TPA assemblies from a single path, - // and have no native images, we can ignore that complication. - } - while (FindNextFileA(fileHandle, &findData)); - FindClose(fileHandle); - } -} -// -#elif LINUX -// POSIX directory search for .dll files -void BuildTpaList(const char* directory, const char* extension, std::string& tpaList) -{ - DIR* dir = opendir(directory); - struct dirent* entry; - int extLength = strlen(extension); - - while ((entry = readdir(dir)) != NULL) - { - // This simple sample doesn't check for symlinks - std::string filename(entry->d_name); - - // Check if the file has the right extension - int extPos = filename.length() - extLength; - if (extPos <= 0 || filename.compare(extPos, extLength, extension) != 0) - { - continue; - } - - // Append the assembly to the list - tpaList.append(directory); - tpaList.append(FS_SEPARATOR); - tpaList.append(filename); - tpaList.append(PATH_DELIMITER); - - // Note that the CLR does not guarantee which assembly will be loaded if an assembly - // is in the TPA list multiple times (perhaps from different paths or perhaps with different NI/NI.dll - // extensions. Therefore, a real host should probably add items to the list in priority order and only - // add a file if it's not already present on the list. - // - // For this simple sample, though, and because we're only loading TPA assemblies from a single path, - // and have no native images, we can ignore that complication. - } -} -#endif - -// Callback function passed to managed code to facilitate calling back into native code with status -int ReportProgressCallback(int progress) -{ - // Just print the progress parameter to the console and return -progress - printf("Received status from managed code: %d\n", progress); - return -progress; -} diff --git a/core/hosting/HostWithCoreClrHost/src/coreclrhost.h b/core/hosting/HostWithCoreClrHost/src/coreclrhost.h deleted file mode 100644 index 3dddab118dd..00000000000 --- a/core/hosting/HostWithCoreClrHost/src/coreclrhost.h +++ /dev/null @@ -1,127 +0,0 @@ -// Retrieved from https://github.com/dotnet/runtime/blob/main/src/coreclr/src/hosts/inc/coreclrhost.h - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// -// APIs for hosting CoreCLR -// - -#ifndef __CORECLR_HOST_H__ -#define __CORECLR_HOST_H__ - -#if defined(_WIN32) && defined(_M_IX86) -#define CORECLR_CALLING_CONVENTION __stdcall -#else -#define CORECLR_CALLING_CONVENTION -#endif - -// For each hosting API, we define a function prototype and a function pointer -// The prototype is useful for implicit linking against the dynamic coreclr -// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary) -#define CORECLR_HOSTING_API(function, ...) \ - extern "C" int CORECLR_CALLING_CONVENTION function(__VA_ARGS__); \ - typedef int (CORECLR_CALLING_CONVENTION *function##_ptr)(__VA_ARGS__) - -// -// Initialize the CoreCLR. Creates and starts CoreCLR host and creates an app domain -// -// Parameters: -// exePath - Absolute path of the executable that invoked the ExecuteAssembly (the native host application) -// appDomainFriendlyName - Friendly name of the app domain that will be created to execute the assembly -// propertyCount - Number of properties (elements of the following two arguments) -// propertyKeys - Keys of properties of the app domain -// propertyValues - Values of properties of the app domain -// hostHandle - Output parameter, handle of the created host -// domainId - Output parameter, id of the created app domain -// -// Returns: -// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed -// -CORECLR_HOSTING_API(coreclr_initialize, - const char* exePath, - const char* appDomainFriendlyName, - int propertyCount, - const char** propertyKeys, - const char** propertyValues, - void** hostHandle, - unsigned int* domainId); - -// -// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host. -// -// Parameters: -// hostHandle - Handle of the host -// domainId - Id of the domain -// -// Returns: -// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed -// -CORECLR_HOSTING_API(coreclr_shutdown, - void* hostHandle, - unsigned int domainId); - -// -// Shutdown CoreCLR. It unloads the app domain and stops the CoreCLR host. -// -// Parameters: -// hostHandle - Handle of the host -// domainId - Id of the domain -// latchedExitCode - Latched exit code after domain unloaded -// -// Returns: -// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed -// -CORECLR_HOSTING_API(coreclr_shutdown_2, - void* hostHandle, - unsigned int domainId, - int* latchedExitCode); - -// -// Create a native callable function pointer for a managed method. -// -// Parameters: -// hostHandle - Handle of the host -// domainId - Id of the domain -// entryPointAssemblyName - Name of the assembly which holds the custom entry point -// entryPointTypeName - Name of the type which holds the custom entry point -// entryPointMethodName - Name of the method which is the custom entry point -// delegate - Output parameter, the function stores a native callable function pointer to the delegate at the specified address -// -// Returns: -// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed -// -CORECLR_HOSTING_API(coreclr_create_delegate, - void* hostHandle, - unsigned int domainId, - const char* entryPointAssemblyName, - const char* entryPointTypeName, - const char* entryPointMethodName, - void** delegate); - -// -// Execute a managed assembly with given arguments -// -// Parameters: -// hostHandle - Handle of the host -// domainId - Id of the domain -// argc - Number of arguments passed to the executed assembly -// argv - Array of arguments passed to the executed assembly -// managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint). -// exitCode - Exit code returned by the executed assembly -// -// Returns: -// HRESULT indicating status of the operation. S_OK if the assembly was successfully executed -// -CORECLR_HOSTING_API(coreclr_execute_assembly, - void* hostHandle, - unsigned int domainId, - int argc, - const char** argv, - const char* managedAssemblyPath, - unsigned int* exitCode); - -#undef CORECLR_HOSTING_API - -#endif // __CORECLR_HOST_H__ diff --git a/core/hosting/HostWithHostFxr/readme.md b/core/hosting/HostWithHostFxr/readme.md index c3940269d90..6e893fdf3d3 100644 --- a/core/hosting/HostWithHostFxr/readme.md +++ b/core/hosting/HostWithHostFxr/readme.md @@ -2,9 +2,13 @@ This project demonstrates a way for a native process to host .NET Core using the `nethost` and `hostfxr` libraries. Documentation on the `nethost` and `hostfxr` APIs can be found [here](https://github.com/dotnet/runtime/blob/main/docs/design/features/native-hosting.md). +This sample is part of the [.NET Core hosting tutorial](https://docs.microsoft.com/dotnet/core/tutorials/netcore-hosting). Please see that topic for a more detailed explanation of the sample and the steps necessary to host .NET Core. + +The host is small and bypasses a lot of complexity (thorough error checking, etc.) that a real host would have. Hopefully by remaining simple, though, it will be useful for demonstrating the core concepts of hosting managed .NET Core code in a native process. + ## Key Features -Demonstrates how to locate and initialize .NET Core 3.0 from a non-.NET Core process and subsequently load and call into a .NET Core assembly. +Demonstrates how to locate and initialize .NET Core runtime from a non-.NET Core process and subsequently load and call into a .NET Core assembly. The `nethost` header and library are part of the `Microsoft.NETCore.DotNetAppHost` package and are also installed as a runtime pack by the .NET Core SDK. The library should be deployed alongside the host. This sample uses the files installed with the .NET Core SDK. *Note: The `Microsoft.NETCore.DotNetAppHost` package is a [metapackage](https://docs.microsoft.com/dotnet/core/packages#metapackages) that doesn't actually contain the files. It only references RID-specific packages that contain the files. For example, the package with the actual files for `linux-x64` is `runtime.linux-x64.Microsoft.NETCore.DotNetAppHost`.* diff --git a/core/hosting/README.md b/core/hosting/README.md deleted file mode 100644 index 4754693a133..00000000000 --- a/core/hosting/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Sample .NET Core Hosts - -This folder contains sample code demonstrating how to host managed .NET Core code in a native process. These hosts bypass the usual `dotnet` host and launch managed code directly. - -There are two samples demonstrating two different hosting interfaces for .NET Core. - -1. The [HostWithHostFxr](HostWithHostFxr) folder demonstrates how to host the .NET Core runtime using the `nethost` and `hostfxr` libraries' APIs. These APIs were introduced in .NET Core 3.0 and are the recommended method of hosting .NET Core 3.0 and above. These entry points handle the complexity of finding and setting up the runtime for initialization. This host demonstrates calling from native code into a static managed method and passing it a message to display. -1. The [HostWithCoreClrHost](HostWithCoreClrHost) folder demonstrates how to host the .NET Core runtime using the newer `coreclrhost.h` API. This API is the preferred method of hosting .NET Core 2.2 and below. This host demonstrates calling from native code into a static managed method and supplying a function pointer for the managed code to use to call back into the host. - -These hosts are small and bypass a lot of complexity (probing for assemblies in multiple locations, thorough error checking, etc.) that a real host would have. Hopefully by remaining simple, though, they will be useful for demonstrating the core concepts of hosting managed .NET Core code in a native process. Other (more real-world) hosts which may be useful as a guide can be found in .NET Core product source in the [dotnet/runtime](https://github.com/dotnet/runtime/tree/main/src/coreclr/src/hosts) repository. - -These samples are part of the [.NET Core hosting tutorial](https://docs.microsoft.com/dotnet/core/tutorials/netcore-hosting). Please see that topic for a more detailed explanation of the samples and the steps necessary to host .NET Core.