I realize this sort of question has been asked before, but I have a very specific (and a rather complicated) case that is subtly different, so the usual solutions either do not work or do not apply.
Basically, I have a console app which is launched by a VSIX debugger launcher. The purpose of this app is to load a hosted DLL, establish the appropriate environment, and allow debugging of the DLL's source code from Visual Studio the same way a normal C# project would be debugged. The difference is that this project is not an executable, but a library, and so it needs a host (i.e. the console app in question). It's all very similar to how ASP.NET projects work with IIS/IIS Express - it's just that I wrote a custom host and I manage its launching from my custom VSIX.
The custom host app is a .NET Core Console app and the debugger launches it without any windows. This is deliberate, since it needs no interactive input and all output is redirected to the Visual Studio's debugger session (i.e. the Events tab).
The app is also generic, so it can't know the name of the debugged project until it's actually started. On top of that, I can have multiple instances of Visual Studio debugging multiple different projects at the same time!
I would really like to ease differentiation of these processes in Task Manager, so that they each showed as the name of the specific DLL project that is being hosted in each respective instance. My attempts so far have been:
// 1. This crashes with InvalidOperationException because there is no window.
Console.Title = loadedDllProjectName;
// 2. This doesn't crash, but has no effect, either.
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
...
SetWindowText(Process.GetCurrentProcess().MainWindowHandle, loadedDllProjectName);
FWIW, the Task Manager shows the process under its default image name and lists it among background processes. The latter is fine and expected. But I would like to change the former. How?
UPDATE According to this, my pursuit might sadly be hollow. Still hoping for an encouraging hint, though!