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

怎甘沉沦 提交于 2020-01-03 07:01:13

问题


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

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

My code is:

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

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.

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

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

Thanks


回答1:


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



来源:https://stackoverflow.com/questions/47326217/running-a-net-core-app-dll-with-cmd-by-using-process-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!