我有一个运行不同测试仪应用程序的测试运行器应用程序。
根据运行程序是通过dotnet
CLI命令(例如,>dotnet runner.dll -t tester1
)还是通过简单运行已发布的.exe
文件(例如,>runner.exe -t tester1
)来启动,我想要为测试人员应用可执行文件建立不同的路径。
最好检查一下?
这就是我的使用方式(这是一个POC应用程序,这里我只需要2种情况):
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
}
};
}
}
答案 0 :(得分:2)
一种选择是使用Process.GetCurrentProcess
获取当前进程,然后使用其ProcessName
属性:
if (Process.GetCurrentProcess().ProcessName == "dotnet")
{
...
}