Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 200
yntnm Avatar asked Nov 16 '17 09:11

yntnm


People also ask

How do I run a .NET core console application dll?

In . NET Core, it runs from the dll, so you have to just run the application by running the command prompt and using the command - dotnet run. Open your command prompt and go to that folder where your application persists.

How do I run a DLL in DotNet?

The dotnet run command is used in the context of projects, not built assemblies. If you're trying to run a framework-dependent application DLL instead, you must use dotnet without a command. For example, to run myapp.dll, use: .NET CLI. dotnet myapp.dll.

How to install a DotNet core application as a Windows service?

To install a .Net Core application as a windows service just create a batch file called run.bat in your application root that contains the following command: dotnet run You can register this batch file as a windows service called “testservice” by dropping NSSM.EXE into your application directory and running the following:

How to start processes from C #on NET Core Applications?

Today we will see how we can start processes from C# on .NET Core applications and how it can be useful in a real scenario 1. Unzip from CLI 2. Use CLI from C#

How to work with ASP NET Core from command line?

In this article, let's see how to work with ASP.NET Core from Command Line. First, we have to see the installation folder of ASP.NET Core; I have installed it in “E Drive”. Open the command prompt in Administrative mode and type “dotnet --help”.


1 Answers

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

like image 140
Juergen Gutsch Avatar answered Oct 25 '22 07:10

Juergen Gutsch