运行 C#应用程序dll

Run a dll of application through C#

我正在尝试通过 C# 代码调用接受命令行参数的 dll 文件。

当我直接从 cmd window 尝试时,它可以工作,但如果我尝试从 C# 调用它,它会显示以下错误:"No application is associated with the specified file for this operation"

示例 cmd 命令 - C:\Users\user name\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);
 }

需要帮助 this.please 注意没有 exe 文件 这个需要调用的应用程序有一个 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);