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

查看:507
本文介绍了通过使用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\release\PublishOutput\proces.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,区域性=中性,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\release\PublishOutput\,以确保它在与在控制台中直接调用dotnet process.dll相同的环境中运行

It seems you also need to set the WorkingDirectory to path\release\PublishOutput\ 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天全站免登陆