使用 process.start 使用 cmd 运行 .NET 核心应用程序 (.dll) [英] Running a .NET core app (.dll) with cmd by using process.start

查看:55
本文介绍了使用 process.start 使用 cmd 运行 .NET 核心应用程序 (.dll)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to .NET Core 2.0, so i might be doing this all wrong, if so let me know.

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

I have a .NET core 2.0 app that should be cross platform, hence the app is a .dll console application, and it does work fine on all platforms.

我正在尝试实现一种看门狗,在必要的过程中会自我复制,并以同样的方式调用

I'm trying to implement kind of a watchdog, that in case of necessary process will duplicate itself, and by the same way it was called

> $ dotnet process.dll

我的代码是:

var process = new Process
{
   StartInfo = new ProcessStartInfo
   {
       FileName = "dotnet",
       Arguments = "path
eleasePublishOutputproces.dll"
       UseShellExecute = true,
       RedirectStandardOutput = false,
       RedirectStandardError = false,
       CreateNoWindow = true
     }

 };

 process.Start();

问题是当进程运行此代码时,我收到以下异常

The problem is that when the process runs this code, i'm getting the following exception

未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集System.Runtime,版本=4.2.0.0,Culture=neutral,PublicKeyToken=sometoken"或其依赖项之一.系统找不到指定的文件.

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 的内容,我也不知道这是否可能?

I can't find any mention of ruining dotnet from code, and i don't know even if this is possible?

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

Is it possible? Is .NET core process able to duplicate itself?

谢谢

推荐答案

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

It seems you also need to set the WorkingDirectory to path eleasePublishOutput to be sure it is running in the same environment as calling dotnet process.dll directly in the console

这篇关于使用 process.start 使用 cmd 运行 .NET 核心应用程序 (.dll)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆