2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
#if NETCOREAPP
5
+ using System ;
5
6
using System . IO ;
6
7
using System . Runtime . InteropServices ;
7
8
using Xunit ;
@@ -10,14 +11,31 @@ namespace Microsoft.Extensions.CommandLineUtils
10
11
{
11
12
public class DotNetMuxerTests
12
13
{
13
- [ Fact ( Skip = "https://github.com/dotnet/aspnetcore/issues/24082" ) ]
14
+ [ Fact ]
14
15
public void FindsTheMuxer ( )
15
16
{
16
- var muxerPath = DotNetMuxer . MuxerPath ;
17
+
18
+ var muxerPath = DotNetMuxer . TryFindMuxerPath ( GetDotnetPath ( ) ) ;
17
19
Assert . NotNull ( muxerPath ) ;
18
20
Assert . True ( File . Exists ( muxerPath ) , "The file did not exist" ) ;
19
21
Assert . True ( Path . IsPathRooted ( muxerPath ) , "The path should be rooted" ) ;
20
22
Assert . Equal ( "dotnet" , Path . GetFileNameWithoutExtension ( muxerPath ) , ignoreCase : true ) ;
23
+
24
+ static string GetDotnetPath ( )
25
+ {
26
+ // Process.MainModule is app[.exe] and not `dotnet`. We can instead calculate the dotnet SDK path
27
+ // by looking at the shared fx directory instead.
28
+ // depsFile = /dotnet/shared/Microsoft.NETCore.App/6.0-preview2/Microsoft.NETCore.App.deps.json
29
+ var depsFile = ( string ) AppContext . GetData ( "FX_DEPS_FILE" ) ;
30
+ return Path . GetFullPath ( Path . Combine ( Path . GetDirectoryName ( depsFile ) , ".." , ".." , ".." , "dotnet" + ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ".exe" : "" ) ) ) ;
31
+ }
32
+ }
33
+
34
+ [ Fact ]
35
+ public void ReturnsNullIfMainModuleIsNotDotNet ( )
36
+ {
37
+ var muxerPath = DotNetMuxer . TryFindMuxerPath ( @"d:\some-path\testhost.exe" ) ;
38
+ Assert . Null ( muxerPath ) ;
21
39
}
22
40
}
23
41
}
0 commit comments