我正在尝试调用通过C#代码接受命令行参数的dll文件。
当我直接从cmd窗口尝试运行时,但是我尝试从C#调用它时,显示以下错误:“没有应用程序与此操作的指定文件关联”
示例cmd命令-C:\ Users \用户名\ source \ repos \ addconsole \ addconsole \ bin \ Debug \ netcoreapp3.1> dotnet AddConsole.dll 1 2 3
static void Main(string[] args)
{
var proc1 = new ProcessStartInfo();
proc1.UseShellExecute = true;
proc1.WorkingDirectory = @"C:\Users\user name\source\repos\addconsole\addconsole\bin\Debug\netcoreapp3.1";
proc1.FileName = @"addconsole.dll";
proc1.Arguments = "1 2 3";
Process.Start(proc1);
}
需要对此文件的帮助。请注意,该应用程序没有一个需要运行主要功能的dll文件,该文件需要被调用。
您实际上需要调用dotnet.exe
并提供相关参数。因此,将FileName设置为dotnet,其余设置为参数。
var proc1 = new ProcessStartInfo();
proc1.UseShellExecute = true;
proc1.WorkingDirectory = @"C:\Users\user name\source\repos\addconsole\addconsole\bin\Debug\netcoreapp3.1";
proc1.Arguments = "\"addconsole.dll\" 1 2 3";
proc1.FileName = "dotnet.exe";
Process.Start(proc1);