Running a .NET-based Worker on Windows and Linux Batch Pools in OneCompute

If the application worker targets .NET Framework, deployment on Windows pools in OneCompute is straight forward, because .NET Framework comes with Windows. This requires the worker to be run on Windows, however.

By targeting .NET instead, a worker may run on both Linux and Windows nodes when deployed to OneCompute. When creating an Azure Batch pool with Linux nodes, there are two options availble for running the worker on Linux:

  • Containerized worker
  • Non-containerized worker

This section describes how to create and deploy the latter, non-containerized workers.

What is a Self-contained Application Worker Host?

The Worker Host is the executable invoked by the execution environment. When running the worker in Azure Batch, the Worker Host must be a console application.

To run a .NET-based worker host on a non-containerized Azure Batch node, the .NET runtime must be present. .NET supports two ways of application deployment:

  • Framework dependent deployment
  • Self-contained deployment

The Framework dependent deployment of an application requires that .NET is preinstalled on the machine. This reduces the size of the application to just the application code. Moreover, platform neutral binaries targeting multiple platforms can be deployed.

The Self-contained deployment option means that the .NET runtime and libraries are deployed with the application itself. This makes deployment easier, because no predeployment of .NET is needed. The deployment size is higher for self-contained deployments, due to the need to deploy the .NET runtime with the application. The self-contained application option is well suited for OneCompute applications, because the application binaries can be deployed just as easily as a .NET Framework application.

How to Create a Self-contained Application Worker for execution on Windows and Linux

In order to deploy a self-contained application worker to OneCompute, a separate executable, the application worker host, must be created. The project should be created as a .NET Console application .csproj targeting .NET 8.0:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

A reference to the package DNV.One.Compute.WorkerHost.Kernel.Azure should be added. The entry point of the WorkerHost application should look like this:

    using DNV.One.Compute.WorkerHost.Kernel.Azure;

    /// <summary>
    /// Application specific workerhost needed to build a self-contained .NET applications.
    /// </summary>
    internal class Program
    {
        /// <summary>
        /// Main entry point.
        /// </summary>
        /// <param name="args">Command-line arguments.</param>
        /// <returns>Exit code.</returns>
        internal static async Task<int> Main(string[] args) =>
            await WorkerHost.Run(args);
    }

How to Deploy a Self-contained Application Worker

Assuming that the self-contained worker host is named MySelfContainedWorkerHost, the following steps should be done in order to create an application package for it that can be deployed to OneCompute the normal way:

  • Publish the application worker host as a self-contained .NET application
  • Create the application package
  • Deploy the application package to OneCompute

Publish the Application Worker Host as a Self-contained Application

The .NET CLI (dotnet) is required to create a self-contained .NET application. Open a command prompt in the directory of the .csproj of the application workerhost (MySelfContainedWorkerHost.csproj) and issue the following command:

dotnet publish -c Release -r <RID>  --self-contained true -f net8.0

RID itentifies the target platform:

Platform RID
Windows x64 win-x64
Linux x64 linux-x64

The binaries are platform specific, and can be found in a subfolder of the normal build folder named <RID>/publish. For instance, if the target platform is Linux x64, the binaries of the self-contained application will be in the sub folder named linux-x64/publish.

Create the Application Package for the Application Worker Host

The binaries in the publish folder should be zipped into a single .zip file.

Deploy the Application Package to OneCompute

The application package .zip file can be deployed by creating an Application in the OneCompute portal and upload it through the OneCompute portal.

How to Run a Self-contained Worker Host

First, the application package for the self-contained worker must be deployed to OneCompute, as described above. In order to run an application worker host, OneCompute needs to know which executable to invoke. This is set in the WorkUnit.Command property on each WorkUnit created in the job. The name of the executable file depends on the target platform. dotnet publish creates a file without extension when targeting Linux, while for Windows, the standard .exe extension is used.

Platform Executable name Example
Windows <application name>.exe MySelfContainedWorkerHost.exe
Linux <application name> MySelfContainedWorkerHost

Code example:

WorkUnit wu = ...
wu.Command = <executable name>; // This is required to run a .NET-based self-contained executable.

Relevant Links

  • .NET application publishing overview
  • Publish .NET apps with the .NET CLI
  • Trim self-contained deployments and executables
  • Edit this page
In this article
Back to top Copyright © DNV AS. All rights reserved.