Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,29 @@ load_assembly_and_get_function_pointer_fn DotnetEnvironment::get_dotnet_load_ass
// Name: DotnetEnvironment::get_dotnet
//
// Description:
// Load the .NET runtime from the configuration path and DOTNET_ROOT environment variable, and get the hostfxr handle.
// Load the .NET runtime from the configuration path and get the hostfxr handle.
// Supports both framework-dependent (3P: DOTNET_ROOT points to system .NET install)
// and self-contained (1P: all runtime DLLs in the language directory) deployments.
//
hostfxr_handle DotnetEnvironment::get_dotnet(const char_t *config_path){
LOG("DotnetEnvironment::get_dotnet");
hostfxr_handle cxt = nullptr;

hostfxr_initialize_parameters params = { 0 };
params.size = sizeof(hostfxr_initialize_parameters);
params.host_path = nullptr;

// Set host_path to the extension DLL in the language directory. This tells hostfxr
// where the app lives, enabling self-contained runtimeconfig ("includedFrameworks")
// to resolve coreclr.dll from the same directory. For framework-dependent configs,
// hostfxr uses dotnet_root to find the system runtime instead.
//
string_t host_path = m_root_path + STR("\\Microsoft.SqlServer.CSharpExtension.dll");
params.host_path = host_path.c_str();
params.dotnet_root = nullptr;

// Get the required size for the environment variable
// If DOTNET_ROOT is set (e.g., by the coordinator for 1P, or by the system for 3P),
// pass it to hostfxr for framework-dependent resolution.
//
DWORD requiredSize = GetEnvironmentVariableW(L"DOTNET_ROOT", nullptr, 0);
std::vector<wchar_t> dotnet_root_buffer;
if (requiredSize > 0)
Expand Down