Search code examples
windows.net-corewindows-serverdotnet-cli

Force closing a running dotnet process


We are trying to have a CI/CD pipeline strategy which involves force closing/killing a running dotnet process which is running on our VisualCron server:

  1. Turn off the VC Job
  2. Force close/kill the process (????)
  3. Deploy the latest assemblies
  4. Restart the VC Job

The part that we are stuck on is that this VC server is running numerous jobs. In the past this wasn't an issue because a .NET Framework application was named appropriately 'somejob.exe'. However, with dotnet every process is running as dotnet.exe.

Is there a way to target a specific instance of a running dotnet.exe process to close/kill based on the entry point assembly passed into dotnet.exe? For example, dotnet c:\jobs\somejob.dll -- we need to close/kill just this job (not the other dotnet jobs running).


Solution

  • I found a way to utilize the taskkill tool to target a specific dotnet application, though the usage may vary based on the scenario.

    In our scenario, our assemblies are named in a very unique fashion... All of our applications are namespaced out very well CompanyName.ProductName.ConsoleAppName.dll. This allows us to use the filter command and filter based on a specific module:

    taskkill /FI "Modules eq CompanyName.ProductName.ConsoleAppName.dll"


    Clearly, had our assemblies not been named in a unique fashion, this would not work well, for example, if we had our console app named App.dll.