-
Notifications
You must be signed in to change notification settings - Fork 380
/
DotnetMuxer.cs
55 lines (42 loc) · 1.38 KB
/
DotnetMuxer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NET6_0_OR_GREATER
using System.IO;
using System.Runtime.InteropServices;
namespace System.CommandLine.Suggest;
internal static class DotnetMuxer
{
public static FileInfo Path { get; }
static DotnetMuxer()
{
var muxerFileName = ExecutableName("dotnet");
var fxDepsFile = GetDataFromAppDomain("FX_DEPS_FILE");
if (string.IsNullOrEmpty(fxDepsFile))
{
return;
}
var muxerDir = new FileInfo(fxDepsFile).Directory?.Parent?.Parent?.Parent;
if (muxerDir is null)
{
return;
}
var muxerCandidate = new FileInfo(System.IO.Path.Combine(muxerDir.FullName, muxerFileName));
if (muxerCandidate.Exists)
{
Path = muxerCandidate;
}
else
{
throw new InvalidOperationException("no muxer!");
}
}
public static string GetDataFromAppDomain(string propertyName)
{
return AppContext.GetData(propertyName) as string;
}
public static string ExecutableName(this string withoutExtension) =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? withoutExtension + ".exe"
: withoutExtension;
}
#endif