关于 c#:使用 process.start 使用 cmd 运行 .NET 核心应用程序(.dll) | 珊瑚贝

Running a .NET core app (.dll) with cmd by using process.start


我是 .NET Core 2.0 的新手,所以我可能做错了,如果是这样,请告诉我。

我有一个应该是跨平台的 .NET core 2.0 应用程序,因此该应用程序是一个 .dll 控制台应用程序,它在所有平台上都可以正常工作。

我正在尝试实现一种看门狗,在必要的情况下,它会复制自己,并且以同样的方式被称为

1
> $ dotnet process.dll

我的代码是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var process = new Process
{
   StartInfo = new ProcessStartInfo
   {
       FileName =“dotnet”,
       Arguments =“path\
elease\\PublishOutput\\proces.dll”

       UseShellExecute = true,
       RedirectStandardOutput = false,
       RedirectStandardError = false,
       CreateNoWindow = true
     }

 };

 process.Start();

问题是当进程运行这段代码时,我得到了以下异常

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=sometoken’ or one of its dependencies. The system cannot find the file specified.

我找不到任何关于从代码中破坏 dotnet 的内容,我也不知道这是否可能?

有可能吗? .NET 核心进程是否能够自我复制?

谢谢

  • 我可以使用 .NET Core API 调用此代码吗? (.NET Core 2.1)我无法让它工作
  • Microsoft 建议为 Core Apps 设置 UseShellExecute = false


看来您还需要将 WorkingDirectory 设置为 path\
elease\\PublishOutput\\ 以确保它在与直接在控制台中调用 dotnet process.dll 相同的环境中运行


来源:https://www.codenong.com/47326217/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8727.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?