From 2ed37ae81ce4fbd76bd5d40fc1f0e89c1d5e524f Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Wed, 13 Oct 2021 16:05:28 -0700 Subject: [PATCH 1/3] Remove duplicate entries from dotnet --info --- .../HostActivation.Tests/NativeHostApis.cs | 46 +++++++++++++++++++ src/native/corehost/hostmisc/utils.cpp | 1 + 2 files changed, 47 insertions(+) diff --git a/src/installer/tests/HostActivation.Tests/NativeHostApis.cs b/src/installer/tests/HostActivation.Tests/NativeHostApis.cs index aaabf8e571bcd..d9feb540d70bc 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/utils.cpp b/src/native/corehost/hostmisc/utils.cpp index 21cc7e9c9b49e..f0d805e3088da 100644 --- a/src/native/corehost/hostmisc/utils.cpp +++ b/src/native/corehost/hostmisc/utils.cpp @@ -305,6 +305,7 @@ void get_framework_and_sdk_locations(const pal::string_t& dotnet_dir, std::vecto { for (pal::string_t dir : global_dirs) { + remove_trailing_dir_seperator(&dir); // avoid duplicate paths if (!pal::are_paths_equal_with_normalized_casing(dir, dotnet_dir_temp)) { From 61b7bc2c23367337948032aa0021b882d52124f1 Mon Sep 17 00:00:00 2001 From: vitek-karas Date: Thu, 14 Oct 2021 05:08:28 -0700 Subject: [PATCH 2/3] Remove trailing slashes from globally registered locations as well --- src/native/corehost/hostmisc/pal.windows.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index e50ebdc9313d0..2ec5547ebc40a 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)) { From 2ba1cf9190c81458a5ef3b1d2471e14ba372c4d8 Mon Sep 17 00:00:00 2001 From: vitek-karas Date: Thu, 14 Oct 2021 06:25:16 -0700 Subject: [PATCH 3/3] PR feedback --- src/native/corehost/hostmisc/utils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/native/corehost/hostmisc/utils.cpp b/src/native/corehost/hostmisc/utils.cpp index f0d805e3088da..21cc7e9c9b49e 100644 --- a/src/native/corehost/hostmisc/utils.cpp +++ b/src/native/corehost/hostmisc/utils.cpp @@ -305,7 +305,6 @@ void get_framework_and_sdk_locations(const pal::string_t& dotnet_dir, std::vecto { for (pal::string_t dir : global_dirs) { - remove_trailing_dir_seperator(&dir); // avoid duplicate paths if (!pal::are_paths_equal_with_normalized_casing(dir, dotnet_dir_temp)) {