How to check if my .NET Core console app is running as a self-contained app (by running myapp.exe) or if it's running using dotnet myapp.dll?

Viewed 529

I've tried using Environment.CommandLine to check the executable, but that didn't work, it always shows the dll file. Any idea on how to know if myapp.exe file was used to run the app or if dotnet myapp.dll was used instead?

1 Answers

I created a dotnet core console app and ran the following code:

using System;
using System.Diagnostics;

namespace TestApp
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Process.GetCurrentProcess().ProcessName);
    }
  }
}

When running dotnet run it shows dotnet. I built a standalone version dotnet publish -c Release -r win10-x64 and it shows TestApp.

I'm not sure how reliable this is though.

Related