From 8b0cf9ca8ffc13cba0e665d26c161405cd2bcb84 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:09:32 -0700 Subject: [PATCH] [release/6.0] Remove duplicate entries from dotnet --info (#60446) * Remove duplicate entries from dotnet --info * Remove trailing slashes from globally registered locations as well * PR feedback Co-authored-by: Eric StJohn Co-authored-by: vitek-karas --- .../HostActivation.Tests/NativeHostApis.cs | 46 +++++++++++++++++++ src/native/corehost/hostmisc/pal.windows.cpp | 3 ++ 2 files changed, 49 insertions(+) diff --git a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs index aaabf8e571bcd2..d9feb540d70bce 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs @@ -461,6 +461,52 @@ public void Hostfxr_get_dotnet_environment_info_with_multilevel_lookup_only() } } + [Fact] + [PlatformSpecific(TestPlatforms.Windows)] // Multi-level lookup is only supported on Windows. + public void Hostfxr_get_dotnet_environment_info_with_multilevel_lookup_only_self_register_program_files() + { + var f = new SdkResolutionFixture(sharedTestState); + + string expectedFrameworkNames = string.Join(';', new[] + { + "HostFxr.Test.A", + "HostFxr.Test.A", + "HostFxr.Test.B", + }); + + string expectedFrameworkVersions = string.Join(';', new[] + { + "1.2.3", + "3.0.0", + "5.6.7-A", + }); + + string expectedFrameworkPaths = string.Join(';', new[] + { + Path.Combine(f.ProgramFilesGlobalFrameworksDir, "HostFxr.Test.A"), + Path.Combine(f.ProgramFilesGlobalFrameworksDir, "HostFxr.Test.A"), + Path.Combine(f.ProgramFilesGlobalFrameworksDir, "HostFxr.Test.B"), + }); + + using (TestOnlyProductBehavior.Enable(f.Dotnet.GreatestVersionHostFxrFilePath)) + { + // We pass f.WorkingDir so that we don't resolve dotnet_dir to the global installation + // in the native side. + f.Dotnet.Exec(f.AppDll, new[] { "hostfxr_get_dotnet_environment_info", f.WorkingDir }) + .EnvironmentVariable("TEST_MULTILEVEL_LOOKUP_PROGRAM_FILES", f.ProgramFiles) + // Test with a self-registered path the same as ProgramFiles, with a trailing slash. Expect this to be de-duped + .EnvironmentVariable("TEST_MULTILEVEL_LOOKUP_SELF_REGISTERED", Path.Combine(f.ProgramFiles, "dotnet") + Path.DirectorySeparatorChar) + .CaptureStdOut() + .CaptureStdErr() + .Execute() + .Should().Pass() + .And.HaveStdOutContaining("hostfxr_get_dotnet_environment_info:Success") + .And.HaveStdOutContaining($"hostfxr_get_dotnet_environment_info framework names:[{expectedFrameworkNames}]") + .And.HaveStdOutContaining($"hostfxr_get_dotnet_environment_info framework versions:[{expectedFrameworkVersions}]") + .And.HaveStdOutContaining($"hostfxr_get_dotnet_environment_info framework paths:[{expectedFrameworkPaths}]"); + } + } + [Fact] public void Hostfxr_get_dotnet_environment_info_global_install_path() { diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 2a964f06868e79..6ce65baae47916 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -392,11 +392,14 @@ bool pal::get_global_dotnet_dirs(std::vector* dirs) bool dir_found = false; if (pal::get_dotnet_self_registered_dir(&custom_dir)) { + remove_trailing_dir_seperator(&custom_dir); dirs->push_back(custom_dir); dir_found = true; } if (get_default_installation_dir(&default_dir)) { + remove_trailing_dir_seperator(&default_dir); + // Avoid duplicate global dirs. if (!dir_found || !are_paths_equal_with_normalized_casing(custom_dir, default_dir)) {