【问题标题】:How to run "dotnet myDll.dll" from a .net core project?如何从 .net 核心项目运行“dotnet myDll.dll”?
【发布时间】:2020-08-08 04:52:44
【问题描述】:

我在 mac/linux 上有一个 .net 核心项目,我可以使用从终端运行它

         dotnet myDll.dll

我想从我的 c# 项目代码中运行它 - 所以启动 webapp,然后针对它运行 ui 测试。

我试过了

        var path = "path-to-my-dll/myDll.dll");

        var processStartInfo = new ProcessStartInfo(path, "")
        {
            WorkingDirectory = Path.GetDirectoryName(path)
        };

        var process = Process.Start(processStartInfo);

然而,这只是运行终端等价于

        ./myDll.dll

如何调用 dotnet 命令?

【问题讨论】:

  • 您是否尝试将路径设置为dotnet 并将myDll.dll 作为ProcessStartInfo 中的第一个参数传递?

标签: c# linux macos .net-core


【解决方案1】:

感谢 huysentruitw 和 Execute dotnet command with Process in C#

var processStartInfo = new ProcessStartInfo(expected, "")
        {
            FileName = "dotnet",
            Arguments = "myDll.dll",
            WorkingDirectory = Path.GetDirectoryName(path)
        };

【讨论】:

    【解决方案2】:

    您应该能够将dotnet 作为fileNamemyDll.dll 作为启动参数传递给ProcessStartInfo constructor,如下所示:

    var processStartInfo = new ProcessStartInfo("dotnet", "myDll.dll")
    {
        WorkingDirectory = Path.GetDirectoryName(path),
    };
    
    var process = Process.Start(processStartInfo);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多