Skip to content

Commit dd737de

Browse files
nagilsondsplaisted
authored andcommitted
Implement wrapper around hostfxr calls
1 parent 8a4a5dc commit dd737de

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

src/Installer/Microsoft.Dotnet.Installation/Internal/DotnetArchiveExtractor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,9 @@ public void Dispose()
376376
}
377377
}
378378

379-
// TODO: InstallerOrchestratorSingleton also checks existing installs via the manifest. Which should we use and where?
380-
private IEnumerable<ReleaseVersion> GetExistingSdkVersions(DotnetInstallRoot installRoot)
379+
private static IEnumerable<ReleaseVersion> GetExistingSdkVersions(DotnetInstallRoot installRoot)
381380
{
382-
var bundleProvider = new NETBundlesNativeWrapper();
383-
NetEnvironmentInfo environmentInfo = bundleProvider.GetDotnetEnvironmentInfo(installRoot.Path);
381+
var environmentInfo = HostFxrWrapper.getInfo(installRoot.Path!);
384382
return environmentInfo.SdkInfo.Select(sdk => sdk.Version);
385383
}
386384
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
using Microsoft.DotNet.NativeWrapper;
8+
9+
namespace Microsoft.Dotnet.Installation.Internal
10+
{
11+
internal class HostFxrWrapper
12+
{
13+
public static NetEnvironmentInfo getInfo(string installRoot)
14+
{
15+
var bundleProvider = new NETBundlesNativeWrapper();
16+
return bundleProvider.GetDotnetEnvironmentInfo(installRoot); // Could we use get_available_sdks instead to improve perf?
17+
}
18+
19+
public static IEnumerable<DotnetInstall> getInstalls(string installRoot)
20+
{
21+
var environmentInfo = getInfo(installRoot);
22+
var installs = new List<DotnetInstall>();
23+
foreach (var sdk in environmentInfo.SdkInfo.ToList())
24+
{
25+
installs.Add(new DotnetInstall(
26+
new DotnetInstallRoot(installRoot, InstallerUtilities.GetDefaultInstallArchitecture()),
27+
sdk.Version,
28+
InstallComponent.SDK));
29+
}
30+
31+
foreach (var runtime in environmentInfo.RuntimeInfo.ToList())
32+
{
33+
installs.Add(new DotnetInstall(
34+
new DotnetInstallRoot(installRoot, InstallerUtilities.GetDefaultInstallArchitecture()),
35+
runtime.Version,
36+
InstallComponent.Runtime)); // TODO: Determine the correct InstallComponent based on runtime.Name like release manifest does
37+
}
38+
39+
return installs;
40+
}
41+
}
42+
}

src/Installer/dnup/ArchiveInstallationValidator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ private bool ValidateWithHostFxr(string installRoot, ReleaseVersion resolvedVers
7575
{
7676
try
7777
{
78-
var bundleProvider = new NETBundlesNativeWrapper();
79-
NetEnvironmentInfo environmentInfo = bundleProvider.GetDotnetEnvironmentInfo(installRoot); // Could we use get_available_sdks instead to improve perf?
78+
var environmentInfo = HostFxrWrapper.getInfo(installRoot);
8079

8180
if (component == InstallComponent.SDK)
8281
{

0 commit comments

Comments
 (0)