Skip to content

Commit 522d887

Browse files
nagilsondsplaisted
authored andcommitted
Use hostfxr API to get .NET SDKs that are available to that dotnet root
1 parent b86d6ba commit 522d887

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

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

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Linq;
1111
using System.Runtime.InteropServices;
1212
using Microsoft.Deployment.DotNet.Releases;
13+
using Microsoft.DotNet.NativeWrapper;
1314

1415
namespace Microsoft.Dotnet.Installation.Internal;
1516

@@ -401,47 +402,11 @@ public void Dispose()
401402
}
402403
}
403404

404-
// TODO: InstallerOrchestratorSingleton also checks existing installs via the manifest. Which should we use and where?
405-
// This should be cached and more sophisticated based on vscode logic in the future
405+
// TODO: InstallerOrchestratorSingleton also checks existing installs via the manifest. Which should we use and where?
406406
private IEnumerable<ReleaseVersion> GetExistingSdkVersions(DotnetInstallRoot installRoot)
407407
{
408-
if (installRoot.Path == null)
409-
return Enumerable.Empty<ReleaseVersion>();
410-
411-
var dotnetExe = Path.Combine(installRoot.Path, DnupUtilities.GetDotnetExeName());
412-
if (!File.Exists(dotnetExe))
413-
return Enumerable.Empty<ReleaseVersion>();
414-
415-
try
416-
{
417-
var process = new System.Diagnostics.Process();
418-
process.StartInfo.FileName = dotnetExe;
419-
process.StartInfo.Arguments = "--list-sdks";
420-
process.StartInfo.RedirectStandardOutput = true;
421-
process.StartInfo.UseShellExecute = false;
422-
process.StartInfo.CreateNoWindow = true;
423-
process.Start();
424-
var output = process.StandardOutput.ReadToEnd();
425-
process.WaitForExit();
426-
427-
var versions = new List<ReleaseVersion>();
428-
foreach (var line in output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
429-
{
430-
var parts = line.Split(' ');
431-
if (parts.Length > 0)
432-
{
433-
var versionStr = parts[0];
434-
if (ReleaseVersion.TryParse(versionStr, out var version))
435-
{
436-
versions.Add(version);
437-
}
438-
}
439-
}
440-
return versions;
441-
}
442-
catch
443-
{
444-
return [];
445-
}
408+
var bundleProvider = new NETBundlesNativeWrapper();
409+
NetEnvironmentInfo environmentInfo = bundleProvider.GetDotnetEnvironmentInfo(installRoot.Path);
410+
return environmentInfo.SdkInfo.Select(sdk => sdk.Version);
446411
}
447412
}

0 commit comments

Comments
 (0)