22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44#if NETCOREAPP
5+ using System ;
56using System . IO ;
67using System . Runtime . InteropServices ;
78using Xunit ;
@@ -10,14 +11,31 @@ namespace Microsoft.Extensions.CommandLineUtils
1011{
1112 public class DotNetMuxerTests
1213 {
13- [ Fact ( Skip = "https://github.com/dotnet/aspnetcore/issues/24082" ) ]
14+ [ Fact ]
1415 public void FindsTheMuxer ( )
1516 {
16- var muxerPath = DotNetMuxer . MuxerPath ;
17+
18+ var muxerPath = DotNetMuxer . TryFindMuxerPath ( GetDotnetPath ( ) ) ;
1719 Assert . NotNull ( muxerPath ) ;
1820 Assert . True ( File . Exists ( muxerPath ) , "The file did not exist" ) ;
1921 Assert . True ( Path . IsPathRooted ( muxerPath ) , "The path should be rooted" ) ;
2022 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 ) ;
2139 }
2240 }
2341}
0 commit comments