### IGV Setup and Usage Example Source: https://github.com/dotnet/runtime/blob/main/docs/design/mono/web/other.md Instructions for unpacking and launching the IdealGraphVisualizer (IGV) on macOS, and an example of dumping JIT IR for a C# method. ```bash $ # unpack zip file $ open idealgraphvisualizer . ``` ```csharp using System; public class Fib { public static int fib (int n) { if (n < 2) return 1; return fib(n-2)+fib(n-1); } public static int Main (string[] args) { int repeat = 1; if (args.Length == 1) repeat = Convert.ToInt32 (args [0]); // Console.WriteLine ("Repeat = " + repeat); if (repeat > 32) { Console.WriteLine ("{0}", fib (repeat)); return 0; } for (int i = 0; i < repeat; i++) if (fib (32) != 3524578) return 1; return 0; } } ``` ```bash $ csc fib.cs $ MONO_JIT_DUMP_METHOD=Fib::fib mono fib.exe cfg_dump: create context for "Fib::fib" ``` -------------------------------- ### Setup and Build zstandard with Meson Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zstd/build/meson/README.md Use these commands to set up the Meson build environment, configure build options, and then build and install the zstandard library. Ensure you are in the meson directory. ```sh meson setup -Dbin_programs=true -Dbin_contrib=true builddir cd builddir ninja # to build ninja install # to install ``` ```sh DESTDIR=./staging ninja install ``` ```sh meson configure ``` -------------------------------- ### Install zlib-ng with LD_PRELOAD Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zlib-ng/README.md This example demonstrates how to use the LD_PRELOAD environment variable to temporarily use zlib-ng instead of the system's zlib library for a dynamically linked program. This method avoids system-wide instability. ```bash LD_PRELOAD=/opt/zlib-ng/libz.so.1.2.13.zlib-ng /usr/bin/program ``` -------------------------------- ### Install cross-compilation dependencies Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/libraries/cross-building.md Install the necessary QEMU and binfmt packages on a Debian-based host. ```bash $ sudo apt-get install qemu qemu-user-static binfmt-support debootstrap ``` -------------------------------- ### Run HelloWorld Sample Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/mono/README.md Navigate to the HelloWorld sample directory and use 'make run' to execute the sample. ```bash cd ../.. make run ``` -------------------------------- ### Get StartAddress from CodeBlockHandle Source: https://github.com/dotnet/runtime/blob/main/docs/design/datacontracts/ExecutionManager.md Retrieves the start address of the JIT-compiled method from a CodeBlockHandle. ```csharp TargetCodePointer IExecutionManager.GetStartAddress(CodeBlockHandle codeInfoHandle) { /* find CodeBlock info for codeInfoHandle.Address*/ return info.StartAddress; } ``` -------------------------------- ### Example of Current SuperFileCheck Anchor Output Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/coreclr/disasm-checks.md This example shows the current format of start and end anchors in SuperFileCheck's JIT disassembly output. These anchors are used to identify the beginning and end of method disassembly. ```assembly ; Assembly listing for method Program:PerformMod_1(uint):uint <-- start anchor ....... ; Total bytes of code 6, prolog size 0, PerfScore 2.10, instruction count 3, allocated bytes for code 6 (MethodHash=e2c7b489) for method Program:PerformMod_1(uint):uint <-- end anchor ``` -------------------------------- ### Start Tracing a Single ETW Provider with Logman Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/debugging/libraries/windows-instructions.md Use Logman to start tracing a specific ETW provider, such as Sockets. You need to use the provider's GUID. The trace output will be saved to a specified .etl file. ```bash logman -start SocketTrace -o %SYSTEMDRIVE%\sockets.etl -p "{e03c0352-f9c9-56ff-0ea7-b94ba8cabc6b}" -ets // Repro logman -stop SocketTrace -ets ``` -------------------------------- ### Download Hello World Source Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/freebsd-instructions.md Fetch the sample application source code from the corefxlab repository. ```sh janhenke@freebsd-frankfurt:~/coreclr-demo/packages % cd ~/coreclr-demo/runtime janhenke@freebsd-frankfurt:~/coreclr-demo/runtime % curl -O https://raw.githubusercontent.com/dotnet/corefxlab/master/demos/CoreClrConsoleApplications/HelloWorld/HelloWorld.cs ``` -------------------------------- ### Automated Android SDK and NDK Installation Script Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/libraries/testing-android.md This bash script automates the download and setup of the Android NDK and SDK, including accepting licenses and installing required platform and build tools. It supports both macOS and Linux. ```bash #!/usr/bin/env bash set -e NDK_VER=r27c ANDROID_CLI_TOOLS_VER=13114758_latest SDK_API_LEVEL=36 SDK_BUILD_TOOLS=36.0.0 if [[ "$OSTYPE" == "darwin"* ]]; then HOST_OS=darwin HOST_OS_SHORT=mac BASHRC=~/.zprofile else HOST_OS=linux HOST_OS_SHORT=linux BASHRC=~/.bashrc fi # download Android NDK export ANDROID_NDK_ROOT=~/android-ndk-${NDK_VER} curl https://dl.google.com/android/repository/android-ndk-${NDK_VER}-${HOST_OS}.zip -L --output ~/andk.zip unzip ~/andk.zip -d $(dirname ${ANDROID_NDK_ROOT}) && rm -rf ~/andk.zip # download Android SDK, accept licenses and download additional packages such as # platform-tools, platforms and build-tools export ANDROID_SDK_ROOT=~/android-sdk curl https://dl.google.com/android/repository/commandlinetools-${HOST_OS_SHORT}-${ANDROID_CLI_TOOLS_VER}.zip -L --output ~/asdk.zip mkdir ${ANDROID_SDK_ROOT} && unzip ~/asdk.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && rm -rf ~/asdk.zip yes | ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-${SDK_API_LEVEL}" "build-tools;${SDK_BUILD_TOOLS}" ``` -------------------------------- ### Setup NuGet Packages Directory Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/freebsd-instructions.md Create and navigate to a directory for storing NuGet packages. ```sh janhenke@freebsd-frankfurt:~/git/coreclr % mkdir ~/coreclr-demo/packages janhenke@freebsd-frankfurt:~/git/coreclr % cd ~/coreclr-demo/packages ``` -------------------------------- ### Get Global GC Mechanisms Source: https://github.com/dotnet/runtime/blob/main/docs/design/datacontracts/GC.md Retrieves an array of global GC mechanisms if they are defined. Reads the start pointer and length of the mechanisms array. ```csharp IReadOnlyList IGC.GetGlobalMechanisms() { if (!target.TryReadGlobalPointer("GCGlobalMechanisms", out TargetPointer? globalMechanismsArrayStart)) return Array.Empty(); uint globalMechanismsLength = target.ReadGlobal("GlobalMechanismsLength"); return ReadGCHeapDataArray(globalMechanismsArrayStart.Value, globalMechanismsLength); } ``` -------------------------------- ### Create a sample console application Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/using-your-build-with-installed-sdk.md Commands to initialize a new .NET console project for testing purposes. ```cmd mkdir HelloWorld cd HelloWorld dotnet new console ``` -------------------------------- ### Getting a Delegate for Runtime Functionality Source: https://github.com/dotnet/runtime/blob/main/docs/design/features/native-hosting.md Starts the .NET runtime and returns a function pointer (delegate) to specific runtime functionalities. This is crucial for interacting with managed code from native applications. ```APIDOC ## Getting a Delegate for Runtime Functionality ### Description Starts the runtime and returns a function pointer to specified functionality of the runtime. ### Method `hostfxr_get_runtime_delegate` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * `host_context_handle` - handle to the initialized host context. * **[.NET 8 and above]** If set to `NULL` the function will operate on the active host context in the process. * `type` - the type of runtime functionality requested: * `hdt_load_assembly_and_get_function_pointer` - entry point which loads an assembly (with dependencies) and returns function pointer for a specified static method. See below for details (Loading and calling managed components) * `hdt_com_activation`, `hdt_com_register`, `hdt_com_unregister` - COM activation entry-points - see [COM activation](https://github.com/dotnet/runtime/tree/main/docs/design/features/COM-activation.md) for more details. * `hdt_load_in_memory_assembly` - IJW entry-point - see [IJW activation](https://github.com/dotnet/runtime/tree/main/docs/design/features/IJW-activation.md) for more details. * `hdt_winrt_activation` **[.NET 3.* only]** - WinRT activation entry-point - see [WinRT activation](https://github.com/dotnet/runtime/tree/main/docs/design/features/WinRT-activation.md) for more details. The delegate is not supported for .NET 5 and above. * `hdt_get_function_pointer` **[.NET 5 and above]** - entry-point which finds a managed method and returns a function pointer to it. See [calling managed functions](#calling-managed-function-net-5-and-above) for details. * `hdt_load_assembly` **[.NET 8 and above]** - entry-point which loads an assembly by its path. See [loading managed components](#loading-managed-components-net-8-and-above) for details. * `hdt_load_assembly_bytes` **[.NET 8 and above]** - entry-point which loads an assembly from a byte array. See [loading managed components](#loading-managed-components-net-8-and-above) for details. * `delegate` - when successful, the native function pointer to the requested runtime functionality. In .NET Core 3.0 the function only works if `hostfxr_initialize_for_runtime_config` was used to initialize the host context. In .NET 5 the function also works if `hostfxr_initialize_for_dotnet_command_line` was used to initialize the host context. Also for .NET 5 it will only be allowed to request `hdt_load_assembly_and_get_function_pointer` or `hdt_get_function_pointer` on a context initialized via `hostfxr_initialize_for_dotnet_command_line`, all other runtime delegates will not be supported in this case. All returned runtime delegates use the `__stdcall` calling convention on x86. ### Request Example None ### Response #### Success Response (0) Indicates successful retrieval of the delegate. #### Response Example None ### Errors - Returns non-zero on failure. ``` -------------------------------- ### Run iOS Sample Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/mono/testing.md Navigate to the iOS directory and execute this command to run the sample. ```bash make run ``` -------------------------------- ### Start Visual Studio with Specific Configurations Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/host/testing.md Starts Visual Studio with the specified solution and configurations for runtime and libraries. Use this if they were built with different configurations than the host. ```console build.cmd -vs Microsoft.DotNet.CoreSetup -rc Release -lc Release ``` -------------------------------- ### Configure and run a Generic Host Source: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Hosting/src/PACKAGE.md Demonstrates initializing a HostBuilder, registering lifecycle event handlers, and starting the host to listen for shutdown signals. ```C# using (IHost host = new HostBuilder().Build()) { var lifetime = host.Services.GetRequiredService(); lifetime.ApplicationStarted.Register(() => { Console.WriteLine("Started"); }); lifetime.ApplicationStopping.Register(() => { Console.WriteLine("Stopping firing"); Console.WriteLine("Stopping end"); }); lifetime.ApplicationStopped.Register(() => { Console.WriteLine("Stopped firing"); Console.WriteLine("Stopped end"); }); host.Start(); // Listens for Ctrl+C. host.WaitForShutdown(); } ``` -------------------------------- ### Bind_TypeWithNoMembers_Wrapper Method Source: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines/net462/Version0/EmptyConfigType.generated.txt A wrapper method for `Bind_TypeWithNoMembers` that includes null checks and calls the core binding logic. This is an example of how generated code might handle initial setup and validation. ```csharp /// Attempts to bind the given object instance to configuration values by matching property names against configuration keys recursively. [InterceptsLocation(@"src-0.cs", 15, 23)] public static void Bind_TypeWithNoMembers_Wrapper(this IConfiguration configuration, object? instance) { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } if (instance is null) { return; } var typedObj = (global::TypeWithNoMembers_Wrapper)instance; BindCore(configuration, ref typedObj, defaultValueIfNotFound: false, binderOptions: null); } ``` -------------------------------- ### Debug Core Dump with lldb and SOS Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/debugging/libraries/unix-instructions.md Use this command to start debugging a .NET crash dump with lldb. Ensure you have SOS installed and specify the runtime path for symbol resolution. ```bash lldb-3.9 -O "settings set target.exec-search-paths " --core ``` ```bash lldb-3.9 -O "settings set target.exec-search-paths /home/parallels/Downloads/System.Drawing.Common.Tests/home/helixbot/dotnetbuild/work/2a74cf82-3018-4e08-9e9a-744bb492869e/Payload/shared/Microsoft.NETCore.App/$(ProductVersion)/" --core /home/parallels/Downloads/System.Drawing.Common.Tests/home/helixbot/dotnetbuild/work/2a74cf82-3018-4e08-9e9a-744bb492869e/Work/f6414a62-9b41-4144-baed-756321e3e075/Unzip/core /home/parallels/Downloads/System.Drawing.Common.Tests/home/helixbot/dotnetbuild/work/2a74cf82-3018-4e08-9e9a-744bb492869e/Payload/shared/Microsoft.NETCore.App/$(ProductVersion)/dotnet ``` -------------------------------- ### Publish and Run HelloiOS Sample Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/ios.md Publishes the sample app and deploys it to the target device or simulator. ```bash ./dotnet.sh publish src/mono/sample/iOS/Program.csproj -c /p:TargetOS= /p:TargetArchitecture=arm64 /p:DeployAndRun=true /p:UseMonoRuntime=false ``` -------------------------------- ### InstanceDataStart Attribute Example Source: https://github.com/dotnet/runtime/blob/main/src/native/managed/cdac/IData.md Shows how the [InstanceDataStart] attribute generates the byte address after the type's last declared field. This is used by container types to expose the start of the per-instance payload. ```csharp [InstanceDataStart] public TargetPointer Data { get; } ``` -------------------------------- ### Example Application Output Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/using-dev-shipping-packages.md This is an example of the expected output when running the published application, showing the .NET version and the path to the core library. ```text Hello World from .NET 11.0.0-dev The location of System.Private.CoreLib.dll is '/path/to/your/app/bin/Debug/net11.0/win-x64/publish/System.Private.CoreLib.dll' ``` -------------------------------- ### Build RISC-V Toolchain and QEMU Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zlib-ng/arch/riscv/README.md Executes the preparation script to download and build the necessary toolchain and QEMU components. ```bash ./prepare_riscv_toolchain_qemu.sh ``` -------------------------------- ### Get Precode Entrypoint from Interior Address Source: https://github.com/dotnet/runtime/blob/main/docs/design/datacontracts/PrecodeStubs.md Computes the entry point of a precode stub given an interior address within it and its kind. This is useful for resolving the actual start of a precode stub when you only have a pointer to an address inside it. ```csharp TargetPointer GetPrecodeEntryPointFromInteriorAddress(TargetCodePointer interiorAddress, bool isFixupPrecode); ``` -------------------------------- ### Install Mono and NuGet Client Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/freebsd-instructions.md Install the Mono runtime and download the NuGet executable to manage dependencies. ```sh janhenke@freebsd-frankfurt:~/coreclr-demo/packages % sudo pkg install mono ``` ```sh janhenke@freebsd-frankfurt:~/coreclr-demo/packages % curl -L -O https://nuget.org/nuget.exe ``` -------------------------------- ### monovm_runtimeconfig_initialize Usage Example Source: https://github.com/dotnet/runtime/blob/main/docs/design/mono/mobile-runtimeconfig-json.md Demonstrates how to use `monovm_runtimeconfig_initialize` with a file path for configuration and a custom cleanup function. ```APIDOC ## Example Usage of monovm_runtimeconfig_initialize ### Description This example shows how to initialize the runtime configuration using a file path and a custom cleanup function. ### Method `int` (return value of `mono_droid_runtime_init`) ### Endpoint N/A (C API function) ### Parameters None directly for this snippet, but it uses `monovm_runtimeconfig_initialize`. ### Request Example ```c void cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data) { free (args); free (user_data); // This may not be needed, depending on if there is anything needs to be freed. } int mono_droid_runtime_init (const char* executable, int managed_argc, char* managed_argv[]) { ...... MonovmRuntimeConfigArguments *arg = (MonovmRuntimeConfigArguments *)malloc (sizeof (MonovmRuntimeConfigArguments)); arg->kind = 0; // Indicates file path arg->runtimeconfig.name.path = "path_to_generated_binary_file"; monovm_runtimeconfig_initialize (arg, cleanup_runtime_config, NULL); monovm_initialize(......); ...... } ``` ### Response #### Success Response (0) Indicates successful initialization of the runtime. #### Response Example N/A ``` -------------------------------- ### Basic Dependency Injection Setup and Usage in C# Source: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.DependencyInjection/src/PACKAGE.md Demonstrates how to set up a ServiceCollection, register a singleton service, build a ServiceProvider, and retrieve a service instance using dependency injection. The example highlights the Inversion of Control (IoC) pattern where the consumer is only aware of the interface. ```csharp ServiceCollection services = new (); services.AddSingleton(); using ServiceProvider provider = services.BuildServiceProvider(); // The code below, following the IoC pattern, is typically only aware of the IMessageWriter interface, not the implementation. IMessageWriter messageWriter = provider.GetService()!; messageWriter.Write("Hello"); public interface IMessageWriter { void Write(string message); } internal class MessageWriter : IMessageWriter { public void Write(string message) { Console.WriteLine($"MessageWriter.Write(message: \"{message}\")"); } } ``` -------------------------------- ### Install dotnet-serve Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/wasm.md Install the dotnet-serve global .NET tool if you don't have it already. This tool is used for serving files over HTTP for browser testing. ```bash dotnet tool install --global dotnet-serve ``` -------------------------------- ### Manage Registry Key Access Control Lists (ACLs) Source: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Win32.Registry.AccessControl/src/PACKAGE.md Use this code to get, modify, and set ACLs for a registry key. Ensure you have the necessary permissions to modify registry security settings. The example demonstrates creating a key, retrieving its ACL, adding a new access rule, and updating the ACL. ```csharp using Microsoft.Win32; using System.Security.AccessControl; // Open a registry key (or create it if it doesn't exist) using RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("TestKey"); if (registryKey == null) { Console.WriteLine("Failed to create or open the registry key."); return; } // Get the current access control list (ACL) for the registry key RegistrySecurity registrySecurity = registryKey.GetAccessControl(); Console.WriteLine("Current Access Control List (ACL):"); Console.WriteLine(registrySecurity.GetSecurityDescriptorSddlForm(AccessControlSections.Access)); // Create a new access rule granting full control to the current user string currentUser = Environment.UserName; RegistryAccessRule accessRule = new RegistryAccessRule(currentUser, RegistryRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow); // Add the new access rule to the ACL registrySecurity.AddAccessRule(accessRule); // Set the updated ACL on the registry key registryKey.SetAccessControl(registrySecurity); // Get and display the updated ACL for the registry key using the second GetAccessControl overload RegistrySecurity updatedRegistrySecurity = registryKey.GetAccessControl(AccessControlSections.Access); Console.WriteLine("Updated Access Control List (ACL):"); Console.WriteLine(updatedRegistrySecurity.GetSecurityDescriptorSddlForm(AccessControlSections.Access)); ``` -------------------------------- ### Start HTTP Server for Browser Testing on Linux/macOS Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/wasm.md Start a local HTTP server using dotnet-serve to test the WebAssembly runtime in a browser. Ensure the directory contains the necessary build artifacts. ```bash dotnet-serve --directory "artifacts/bin/coreclr/browser.wasm.Debug" ``` -------------------------------- ### Install libnethost Target Conditionally Source: https://github.com/dotnet/runtime/blob/main/src/native/corehost/nethost/CMakeLists.txt Installs the libnethost target. On Windows, it installs with stripped symbols; otherwise, it installs directly. ```cmake if (WIN32) install_with_stripped_symbols(libnethost TARGETS corehost) else() install(TARGETS libnethost DESTINATION corehost) endif(WIN32) ``` -------------------------------- ### Install Swift Library Source: https://github.com/dotnet/runtime/blob/main/src/tests/Interop/Swift/SwiftIndirectResult/CMakeLists.txt Installs the compiled Swift dynamic library to the 'bin' directory within the installation prefix. This makes the library accessible after the project is installed. ```cmake install (FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${SOURCE}.dylib DESTINATION bin ) ``` -------------------------------- ### Example Usage of monovm_runtimeconfig_initialize Source: https://github.com/dotnet/runtime/blob/main/docs/design/mono/mobile-runtimeconfig-json.md Demonstrates how to initialize the runtime configuration using a file path and a custom cleanup function. Ensure this is called before monovm_initialize. ```c void cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data) { free (args); free (user_data); // This may not be needed, depending on if there is anything needs to be freed. } int mono_droid_runtime_init (const char* executable, int managed_argc, char* managed_argv[]) { ...... MonovmRuntimeConfigArguments *arg = (MonovmRuntimeConfigArguments *)malloc (sizeof (MonovmRuntimeConfigArguments)); arg->kind = 0; arg->runtimeconfig.name.path = "path_to_generated_binary_file"; monovm_runtimeconfig_initialize (arg, cleanup_runtime_config, NULL); monovm_initialize(......); ...... } ``` -------------------------------- ### Install CLR Targets Source: https://github.com/dotnet/runtime/blob/main/src/coreclr/gc/CMakeLists.txt Installs CLR targets, including conditional installation of 'clrgcexp' for ARM64 and AMD64 architectures. ```cmake install_clr(TARGETS clrgc DESTINATIONS . sharedFramework COMPONENT runtime) if (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64) install_clr(TARGETS clrgcexp DESTINATIONS . sharedFramework COMPONENT runtime) endif (CLR_CMAKE_TARGET_ARCH_ARM64 OR CLR_CMAKE_TARGET_ARCH_AMD64) endif(FEATURE_STANDALONE_GC) ``` -------------------------------- ### Build NativeAOT iOS Sample Source: https://github.com/dotnet/runtime/blob/main/src/mono/sample/iOS-NativeAOT/README.md Commands to build the sample application using different configurations and dependency sources. ```bash make world ``` ```bash make world BUILD_CONFIG=Release TARGET_OS=ios ``` ```bash make world USE_RUNTIME_PACKS=true ``` ```bash make world USE_RUNTIME_PACKS=true BUILD_CONFIG=Release TARGET_OS=ios ``` -------------------------------- ### Skip Installer Build Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/mono/README.md Use this argument with build.sh to skip building the installer, which can speed up the build process if the installer is not needed. ```bash /p:DisableCrossgen=true ``` -------------------------------- ### Display help parameters Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/coreclr/windows-test-instructions.md Lists all supported parameters for the build script. ```batch src\tests\build.cmd -? ``` -------------------------------- ### Install Static Library Source: https://github.com/dotnet/runtime/blob/main/src/native/libs/System.Security.Cryptography.Native/CMakeLists.txt Installs the static version of the System.Security.Cryptography.Native library to a specified destination. This is a standard installation step for static libraries. ```cmake install (TARGETS System.Security.Cryptography.Native.OpenSsl-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) ``` -------------------------------- ### Install Zstandard with Conan Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zstd/README.md Use this command to install pre-built zstd binaries via Conan. Ensure Conan is installed and configured. ```bash conan install --requires="zstd/[*]" --build=missing ``` -------------------------------- ### Example XML Configuration File Source: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Xml/src/PACKAGE.md This is an example of an appsettings.xml file that can be used with the XML configuration provider. It demonstrates nested elements for configuration settings. ```xml example.com Northwind 192.168.0.10 80 ``` -------------------------------- ### Install COMNativeServer Target Source: https://github.com/dotnet/runtime/blob/main/src/tests/Interop/COM/NativeServer/CMakeLists.txt Installs the COMNativeServer shared library to the 'bin' directory during the installation phase. This is typically used when packaging the project for deployment. ```cmake # add the install targets install (TARGETS COMNativeServer DESTINATION bin) ``` -------------------------------- ### hostfxr_initialize_for_dotnet_command_line Source: https://github.com/dotnet/runtime/blob/main/docs/design/features/hosting-layer-apis.md Initializes the hosting components for running a managed application using command-line arguments. ```APIDOC ## hostfxr_initialize_for_dotnet_command_line ### Description Initialize the hosting components for running a managed application. * `argc` / `argv` - command-line arguments * `parameters` - optional additional parameters * `host_context_handle` - if initialization is successful, this receives an opaque value which identifies the initialized host context. See [Native hosting](native-hosting.md#initialize-host-context) ### Method `hostfxr_initialize_for_dotnet_command_line` ### Parameters #### Arguments - **argc** (`int`) - Required - The number of command-line arguments. - **argv** (`const char_t **`) - Required - An array of command-line arguments. - **parameters** (`const hostfxr_initialize_parameters *`) - Optional - Additional initialization parameters. ### Return Value - `int` - 0 on success, or an error code on failure. - **host_context_handle** (`hostfxr_handle *`) - Output parameter that receives a handle to the initialized host context on success. ``` -------------------------------- ### Start Cross-Build Container Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/cross-building.md Initiates a Docker container for cross-building .NET on a specific community-supported platform. Mounts the current directory and sets up the environment for cross-compilation. ```bash docker run --rm -it \ -v $(pwd):/runtime \ -w /runtime \ -e ROOTFS_DIR=/crossrootfs/arm64 \ mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net11.0-cross-freebsd-14-arm64 \ bash ``` -------------------------------- ### Install Executable Target in CMake Source: https://github.com/dotnet/runtime/blob/main/src/native/watchdog/CMakeLists.txt Installs the 'watchdog' executable target to the destination directory. It specifies installation components for different build configurations. ```cmake install_clr(TARGETS watchdog DESTINATIONS . COMPONENT hosts) ``` ```cmake install_clr(TARGETS watchdog DESTINATIONS . COMPONENT nativeaot) ``` -------------------------------- ### Start Android Emulator from Terminal Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/android.md Start an Android emulator from the terminal. This is an alternative to starting it via Android Studio's Device Manager. ```bash $ANDROID_SDK_ROOT/emulator/emulator -avd ``` -------------------------------- ### Initialize NuGet Configuration Source: https://github.com/dotnet/runtime/blob/main/docs/project/dogfooding.md Creates a local NuGet.Config file for the current directory. ```bash dotnet new nugetconfig ``` -------------------------------- ### Install Zlib Headers Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zlib-ng/CMakeLists.txt Installs Zlib header files to the include directory. This is conditional on SKIP_INSTALL_HEADERS and SKIP_INSTALL_ALL flags. It installs zlib.h, zlib_name_mangling.h, and zconf.h. ```cmake if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zlib${SUFFIX}.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RENAME zlib${SUFFIX}.h) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zlib_name_mangling${SUFFIX}.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RENAME zlib_name_mangling${SUFFIX}.h) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zconf${SUFFIX}.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RENAME zconf${SUFFIX}.h) endif() ``` -------------------------------- ### Sample INI Configuration File Source: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Ini/src/PACKAGE.md Example content for an appsettings.ini file used to populate configuration settings. ```INI [Settings] Server=example.com Database=Northwind ``` -------------------------------- ### Install Zlib Libraries Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zlib-ng/CMakeLists.txt Installs the Zlib libraries (runtime, archive, and library files) to their designated installation directories. This is conditional on SKIP_INSTALL_LIBRARIES and SKIP_INSTALL_ALL flags. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) install(TARGETS ${ZLIB_INSTALL_LIBRARIES} EXPORT ${EXPORT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Initial Product Build with Bootstrap Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/cross-building.md Performs the initial build of the .NET product and its bootstrap artifacts for cross-compilation. This is the first step when setting up a new build environment. ```bash ./build.sh clr+libs --cross --arch $arch --os $os --bootstrap ``` -------------------------------- ### Install mockaotsdk with Stripped Symbols Source: https://github.com/dotnet/runtime/blob/main/src/native/corehost/test/mockaotsdk/CMakeLists.txt Installs the mockaotsdk library with stripped symbols, targeting the corehost_test executable. This is useful for reducing the size of the installed artifact. ```cmake install_with_stripped_symbols(mockaotsdk TARGETS corehost_test) ``` -------------------------------- ### hostfxr_initialize_for_dotnet_command_line Source: https://github.com/dotnet/runtime/blob/main/docs/design/features/native-hosting.md Initializes the hosting components for running a managed application by parsing command line arguments. ```APIDOC ## hostfxr_initialize_for_dotnet_command_line ### Description Initializes the hosting components for running a managed application. The command line is parsed to determine the app path, which is used to locate the .runtimeconfig.json and .deps.json files. ### Parameters #### Request Body - **argc** (int) - Required - The number of arguments in the argv array. - **argv** (const char_t *[]) - Required - The command line arguments for running the managed application. - **parameters** (const hostfxr_initialize_parameters *) - Optional - Additional initialization parameters including host_path and dotnet_root. - **host_context_handle** (hostfxr_handle *) - Required - Output parameter that receives an opaque handle to the initialized host context. ### Response #### Success Response (0) - **host_context_handle** (hostfxr_handle) - An opaque value identifying the initialized host context. ``` -------------------------------- ### Install CLR Interpreter Library Source: https://github.com/dotnet/runtime/blob/main/src/coreclr/interpreter/CMakeLists.txt Installs the clrinterpreter target. It's installed to the runtime directory, optionally as part of the shared framework if not statically linked. ```cmake if (FEATURE_STATICALLY_LINKED) install_clr(TARGETS clrinterpreter DESTINATIONS . COMPONENT runtime OPTIONAL) else() install_clr(TARGETS clrinterpreter DESTINATIONS . sharedFramework COMPONENT runtime OPTIONAL) endif() ``` -------------------------------- ### RuntimeConfig.json Example Source: https://github.com/dotnet/runtime/blob/main/docs/design/features/additional-deps.md This JSON structure defines runtime options, including the framework name and version. Ensure the 'version' field matches the expected directory structure for additional dependencies. ```json { "runtimeOptions": { "framework": { "name": "Microsoft.NETCore.App", "version": "2.0.0" } } } ``` -------------------------------- ### Install Runtime Dependencies with Homebrew on macOS Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/macos-requirements.md Execute this script from the repository root after installing Homebrew to download and install all required dependencies for building the runtime. ```bash ./eng/common/native/install-dependencies.sh ``` -------------------------------- ### Example Roll Forward Scenarios Source: https://github.com/dotnet/runtime/blob/main/docs/design/features/roll-forward-on-no-candidate-fx.md Illustrates different scenarios of framework version selection based on desired and available versions, demonstrating default roll-forward logic for production and preview versions. ```text Desired version: 1.0.1 Available versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.1.1, 2.0.1 Chosen version: 1.0.3 ``` ```text Desired version: 1.0.1 Available versions: 1.0.0, 1.1.0-preview1-x, 1.1.0-preview2-x, 1.2.0-preview1-x Chosen version: 1.1.0-preview2-x ``` ```text Desired version: 1.0.1 Available versions: 1.0.0, 1.1.0-preview1-x, 1.2.0, 1.2.1-preview1-x Chosen version: 1.2.0 ``` ```text Desired version: 1.0.1 Available versions: 1.0.0, 2.0.0 Chosen version: there is no compatible version available ``` ```text Desired version: 1.0.1-preview2-x Available versions: 1.0.1-preview2-x, 1.0.1-preview3-x Chosen version: 1.0.1-preview2-x ``` ```text Desired version: 1.0.1-preview2-x Available versions: 1.0.1-preview3-x Chosen version: 1.0.1-preview3-x ``` ```text Desired version: 1.0.1-preview2-x Available versions: 1.0.1, 1.0.2-preview3-x Chosen version: there is no compatible version available ``` -------------------------------- ### Install Podman Source: https://github.com/dotnet/runtime/blob/main/src/native/external/zlib-ng/arch/s390/README.md Install the podman container engine prerequisite. ```bash sudo dnf install podman ``` -------------------------------- ### Start HTTP Server for Browser Testing on Windows Source: https://github.com/dotnet/runtime/blob/main/docs/workflow/building/coreclr/wasm.md Start a local HTTP server using dotnet-serve to test the WebAssembly runtime in a browser. Ensure the directory contains the necessary build artifacts. ```cmd dotnet-serve --directory "artifacts\bin\coreclr\browser.wasm.Debug" ``` -------------------------------- ### General Build and Install Instructions Source: https://github.com/dotnet/runtime/blob/main/src/native/external/libunwind/README.md Standard commands to build and install the libunwind library. Ensure autoreconf is run if building from git. The prefix determines the installation directory. ```bash autoreconf -i # Needed only for building from git. Depends on libtool. ./configure --prefix=PREFIX make make install ``` -------------------------------- ### Install dotnet-trace CLI Tool Source: https://github.com/dotnet/runtime/blob/main/docs/project/linux-performance-tracing.md Install the global dotnet-trace tool using the .NET CLI. This command is used once to set up the tool. ```bash dotnet tool install --global dotnet-trace ``` -------------------------------- ### Build and Run WASI Sample Source: https://github.com/dotnet/runtime/blob/main/src/mono/wasi/README.md Builds and runs a WASI sample application using the locally configured runtime. ```shell ./dotnet.sh build /p:TargetOS=wasi /p:Configuration=Debug /t:RunSample src/mono/sample/wasi/console ``` -------------------------------- ### Defining a New Profiler GUID in C# Source: https://github.com/dotnet/runtime/blob/main/src/tests/profiler/native/README.md When adding a new profiler, you need to define a unique GUID for your profiler in the managed code. Replace 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' with your generated GUID. ```csharp static readonly Guid YourProfilerGuid = new Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); ``` -------------------------------- ### JIT method signature output Source: https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/jit/viewing-jit-dumps.md Example output from DOTNET_JitDisasmSummary showing full method names. ```text MyNamespace.C`2[byte,System.__Canon]:M[int,System.__Canon](byte,System.__Canon,int,System.__Canon) MyNamespace.C`2[int,int]:M[int,int](int,int,int,int) ```