Reputation: 23
I have a test runner app which runs different tester apps.
Depending on the case if the runner app is started via dotnet
CLI command (e.g. >dotnet runner.dll -t tester1
) or via simple running of the published .exe
file (e.g. >runner.exe -t tester1
), I want to build different paths to the tester apps executable files.
How it's better to check this?
That's how I'll use it (it's a POC app, I need only that 2 cases here):
public TesterProcess(bool runViaDotnetCli)
{
TesterInfo = new T();
if (runViaDotnetCli)
{
Process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
// TesterInfo.ExecutableFileName is something like "tester1.dll" here
ArgumentList = {TesterInfo.ExecutableFileName, "--data", "something"},
UseShellExecute = false, CreateNoWindow = false
}
};
}
else
{
Process = new Process
{
StartInfo = new ProcessStartInfo
{
// TesterInfo.ExecutableFileName is something like "tester1.exe" here
FileName = TesterInfo.ExecutableFileName,
ArgumentList = {"--data", "something"},
UseShellExecute = false, CreateNoWindow = false
}
};
}
}
Upvotes: 2
Views: 161
Reputation: 93053
One option for this would be to use Process.GetCurrentProcess
to the get the current process and then use its ProcessName
property:
if (Process.GetCurrentProcess().ProcessName == "dotnet")
{
...
}
Upvotes: 2