Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#if !NET451 && !NET452 && !NET46 && !NET461

using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -43,6 +44,16 @@ private static string TryFindMuxerPath()
fileName += ".exe";
}

var mainModule = Process.GetCurrentProcess().MainModule;
if (!string.IsNullOrEmpty(mainModule?.FileName)
&& Path.GetFileName(mainModule.FileName).Equals(fileName, StringComparison.OrdinalIgnoreCase))
{
return mainModule.FileName;
}

// if Process.MainModule is not available or it does not equal "dotnet(.exe)?", fallback to navigating to the muxer
// by using the location of the shared framework

var fxDepsFile = AppContext.GetData("FX_DEPS_FILE") as string;

if (string.IsNullOrEmpty(fxDepsFile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if NETCOREAPP2_0
using System.IO;
using System.Runtime.InteropServices;
using Xunit;

namespace Microsoft.Extensions.CommandLineUtils
Expand All @@ -15,6 +16,8 @@ public void FindsTheMuxer()
var muxerPath = DotNetMuxer.MuxerPath;
Assert.NotNull(muxerPath);
Assert.True(File.Exists(muxerPath), "The file did not exist");
Assert.True(Path.IsPathRooted(muxerPath), "The path should be rooted");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a Assertion that says the file name is dotnet.exe? Just so we know in case they ever break us.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. On second thought, it would be good to add this to the DotNetMuxer too. Process.MainModule will return the path to corehost in standalone mode ( which is typically renamed to MyAppName.exe). This is muxer, so we should fallback to "dotnet" on PATH in that case.

Assert.Equal("dotnet", Path.GetFileNameWithoutExtension(muxerPath), ignoreCase: true);
}
}
}
Expand Down