Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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