Repository: unoplatform/uno
File: src/Uno.UI.RemoteControl.Server.Processors/HotReload/MetadataUpdates/CompilationWorkspaceProvider.cs (C#)

Code before:
using System.Runtime.Loader;
using Microsoft.Extensions.Logging;
using System.Composition.Hosting;

namespace Uno.UI.RemoteControl.Host.HotReload.MetadataUpdates
{
	internal static class CompilationWorkspaceProvider
	{
		private static string MSBuildBasePath = "";

		public static async Task<(Solution, WatchHotReloadService)> CreateWorkspaceAsync(
			string projectPath,
			IReporter reporter,
			string[] metadataUpdateCapabilities,
			Dictionary<string, string> properties,
			CancellationToken ct)
		{
			if (properties.TryGetValue("UnoHotReloadDiagnosticsLogPath", out var logPath))
			{
				// Sets Roslyn's environment variable for troubleshooting HR, see:
				// https://github.com/dotnet/roslyn/blob/fc6e0c25277ff440ca7ded842ac60278ee6c9695/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs#L72
				Environment.SetEnvironmentVariable("Microsoft_CodeAnalysis_EditAndContinue_LogDir", logPath);

				// Unconditionally enable binlog generation in msbuild. See https://github.com/dotnet/project-system/blob/4210ce79cfd35154dbd858f056bfb9101f290e69/docs/design-time-builds.md?L61
				Environment.SetEnvironmentVariable("MSBUILDDEBUGENGINE", "1");
				Environment.SetEnvironmentVariable("MSBuildDebugEngine", "1"); // For case-insensitive environments like macOS
				Environment.SetEnvironmentVariable("MSBUILDDEBUGPATH", logPath);
			}

			static bool IsValidProperty(string property)
			{
				if (property.Equals("RuntimeIdentifier", StringComparison.OrdinalIgnoreCase))
				{
					// Don't set the runtime identifier since it propagates to libraries as well
					// which do not build using the RuntimeIdentifier being set. For instance, a head
					// building for `iossimulator` will fail if the RuntimeIdentifier is set globally its
					// dependent projects, causing the HR engine to search for pdb/dlls in
					// the bin/Debug/net9.0/iossimulator/*.dll path instead of its original path.

					return false;
				}

				if (property.StartsWith("MSBuild", StringComparison.OrdinalIgnoreCase))
				{
					// Noticeably, don't set the "MSBuildVersion" (Forbidden, will fail workspace).
					return false;
				}

				return true;
			}


Review comment (bug):
```suggestion
				Environment.SetEnvironmentVariable("MSBuildDebugEngine", "1"); // For case-sensitive environments like macOS
```

Code after:
using System.Runtime.Loader;
using Microsoft.Extensions.Logging;
using System.Composition.Hosting;

namespace Uno.UI.RemoteControl.Host.HotReload.MetadataUpdates
{
	internal static class CompilationWorkspaceProvider
	{
		private static string MSBuildBasePath = "";

		public static async Task<(Solution, WatchHotReloadService)> CreateWorkspaceAsync(
			string projectPath,
			IReporter reporter,
			string[] metadataUpdateCapabilities,
			Dictionary<string, string> properties,
			CancellationToken ct)
		{
			if (properties.TryGetValue("UnoHotReloadDiagnosticsLogPath", out var logPath))
			{
				// Sets Roslyn's environment variable for troubleshooting HR, see:
				// https://github.com/dotnet/roslyn/blob/fc6e0c25277ff440ca7ded842ac60278ee6c9695/src/Features/Core/Portable/EditAndContinue/EditAndContinueService.cs#L72
				Environment.SetEnvironmentVariable("Microsoft_CodeAnalysis_EditAndContinue_LogDir", logPath);

				// Unconditionally enable binlog generation in msbuild. See https://github.com/dotnet/project-system/blob/4210ce79cfd35154dbd858f056bfb9101f290e69/docs/design-time-builds.md?L61
				Environment.SetEnvironmentVariable("MSBUILDDEBUGENGINE", "1");
				Environment.SetEnvironmentVariable("MSBuildDebugEngine", "1"); // For case-sensitive environments like macOS
				Environment.SetEnvironmentVariable("MSBUILDDEBUGPATH", logPath);
			}

			static bool IsValidProperty(string property)
			{
				if (property.Equals("RuntimeIdentifier", StringComparison.OrdinalIgnoreCase))
				{
					// Don't set the runtime identifier since it propagates to libraries as well
					// which do not build using the RuntimeIdentifier being set. For instance, a head
					// building for `iossimulator` will fail if the RuntimeIdentifier is set globally its
					// dependent projects, causing the HR engine to search for pdb/dlls in
					// the bin/Debug/net9.0/iossimulator/*.dll path instead of its original path.

					return false;
				}

				if (property.StartsWith("MSBuild", StringComparison.OrdinalIgnoreCase))
				{
					// Noticeably, don't set the "MSBuildVersion" (Forbidden, will fail workspace).
					return false;
				}

				return true;
			}