diff --git a/src/coreclr/scripts/superpmi-collect.proj b/src/coreclr/scripts/superpmi-collect.proj
index ee0d16efd1b0a7..47a70b955aa43d 100644
--- a/src/coreclr/scripts/superpmi-collect.proj
+++ b/src/coreclr/scripts/superpmi-collect.proj
@@ -236,6 +236,7 @@
+
@@ -244,6 +245,7 @@
+
diff --git a/src/coreclr/scripts/superpmi_benchmarks.py b/src/coreclr/scripts/superpmi_benchmarks.py
index a20d39368df8a5..d7f329d67e8c30 100644
--- a/src/coreclr/scripts/superpmi_benchmarks.py
+++ b/src/coreclr/scripts/superpmi_benchmarks.py
@@ -21,7 +21,7 @@
from shutil import copyfile
from coreclr_arguments import *
-from jitutil import run_command, ChangeDir, TempDir
+from jitutil import run_command, ChangeDir, TempDir, copy_directory
# Start of parser object creation.
is_windows = platform.system() == "Windows"
@@ -206,6 +206,56 @@ def build_and_run(coreclr_args, output_mch_name):
"--framework", "net8.0", "--no-restore", "/p:NuGetPackageRoot=" + artifacts_packages_directory,
"-o", artifacts_directory], _exit_on_fail=True)
+ # This is specifically for PowerShell.Benchmarks.
+ # Because we are using '--corerun' when running the benchmarks, it is not able to resolve the PowerShell dependent assemblies.
+ # To make this work, we create a directory called 'core_root' in the directory where the benchmarks_dll lives.
+ # Then we copy the relevant PowerShell dependencies to 'core_root'.
+ # Then we copy the contents of the original 'core_root' to the benchmarks' 'core_root', potentially overwriting any older core dlls.
+ # Then we just use the 'corerun.exe' from the benchmarks' 'core_root'.
+ # We make a copy of 'core_root' as to avoid any potential file-system issues.
+ if benchmarks_dll.endswith("PowerShell.Benchmarks.dll"):
+ benchmarks_dll_dir = os.path.dirname(benchmarks_dll)
+
+ # Create benchmarks' 'core_root'.
+ benchmarks_dll_core_root = os.path.join(benchmarks_dll_dir, "core_root")
+ if not os.path.exists(benchmarks_dll_core_root):
+ os.makedirs(benchmarks_dll_core_root)
+
+ # Begin copy PowerShell dependencies.
+ if is_windows:
+ RID = "win-" + arch
+ elif platform.system() == "Darwin":
+ RID = "osx-" + arch
+ else:
+ RID = "linux-" + arch
+
+ if is_windows:
+ copy_directory(os.path.join(benchmarks_dll_dir, "runtimes/win/lib/net7.0/"), benchmarks_dll_core_root, verbose_copy=True)
+ else:
+ copy_directory(os.path.join(benchmarks_dll_dir, "runtimes/unix/lib/net7.0/"), benchmarks_dll_core_root, verbose_copy=True)
+
+ if is_windows:
+ dir_to_microsoft_management_infrastructure_dll = os.path.join(benchmarks_dll_dir, f"runtimes/{RID}/lib/netstandard1.6/")
+ if os.path.exists(dir_to_microsoft_management_infrastructure_dll):
+ copy_directory(dir_to_microsoft_management_infrastructure_dll, benchmarks_dll_core_root, verbose_copy=True)
+ else:
+ copy_directory(os.path.join(benchmarks_dll_dir, "runtimes/unix/lib/netstandard1.6/"), benchmarks_dll_core_root, verbose_copy=True)
+
+ dir_to_native = os.path.join(benchmarks_dll_dir, f"runtimes/{RID}/native/")
+ if os.path.exists(dir_to_native):
+ copy_directory(dir_to_native, benchmarks_dll_core_root, verbose_copy=True)
+
+ if platform.system() == "Darwin":
+ copy_directory(os.path.join(benchmarks_dll_dir, "runtimes/osx/native/"), benchmarks_dll_core_root, verbose_copy=True)
+ # End copy PowerShell dependencies.
+
+ # Copy the original 'core_root' to the benchmarks' 'core_root'.
+ copy_directory(core_root, benchmarks_dll_core_root, verbose_copy=True)
+
+ # Use benchmarks' 'core_root'.
+ print(f"Using new 'core_root': {benchmarks_dll_core_root}")
+ core_root = benchmarks_dll_core_root
+
# common BDN prefix
collection_command = f"{dotnet_exe} {benchmarks_dll} --corerun {os.path.join(core_root, corerun_exe)} "