Skip to content

Commit

Permalink
Remove duplicate entries from dotnet --info (#60376)
Browse files Browse the repository at this point in the history
* Remove duplicate entries from dotnet --info

* Remove trailing slashes from globally registered locations as well

* PR feedback

Co-authored-by: vitek-karas <[email protected]>
  • Loading branch information
ericstj and vitek-karas authored Oct 14, 2021
1 parent 7752313 commit 1174290
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/installer/tests/HostActivation.Tests/NativeHostApis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/native/corehost/hostmisc/pal.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,14 @@ bool pal::get_global_dotnet_dirs(std::vector<pal::string_t>* 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))
{
Expand Down

0 comments on commit 1174290

Please sign in to comment.