Search by

adachsoft / code-operations-csharp

Arkadiusz Adach

C# and .NET project operations for the AdachSoft code operations contracts.

Package info

gitlab.com/a.adach/code-operations-csharp

Issues

pkg:composer/adachsoft/code-operations-csharp

Statistics

Installs: 21

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.2 2026-12-03 03:04 UTC

This package is auto-updated.

Last update: 2026-12-03 02:05:12 UTC


README

A C#/.NET implementation of the adachsoft/code-operations-contracts API. It discovers installed .NET SDKs and provides project validation, test execution, and application run operations through adachsoft/command-executor-lib.

Installation

Install the package with Composer:

composer require adachsoft/code-operations-csharp

Requirements

  • PHP 8.3 or newer
  • A .NET SDK available as dotnet in PATH, or an explicit executable path
  • Composer dependencies declared by this package

The installed SDK must support the target framework used by the project.

Usage

On Linux or Windows, use the default dotnet executable from PATH:

use AdachSoft\CodeOperationsContracts\ExecutionContextDto;
use AdachSoft\CodeOperationsContracts\RuntimeVo;
use AdachSoft\CodeOperationsCsharp\CsharpCodeOperations;
use AdachSoft\CodeOperationsCsharp\DotnetRuntimeResolver;
use AdachSoft\CommandExecutorLib\SimpleCommandRunner;

$runner = new SimpleCommandRunner();
$resolver = new DotnetRuntimeResolver($runner);
$operations = new CsharpCodeOperations($resolver, $runner);

$context = new ExecutionContextDto(
    projectPath: '/path/to/project',
    runtime: new RuntimeVo('csharp', null),
);

$build = $operations->validate($context);
$tests = $operations->test($context, 'FullyQualifiedName~ParserTest');
$run = $operations->run($context, 'App.csproj', ['--sample-argument']);

When PHP runs in WSL and the .NET SDK is installed on Windows, pass the .exe path explicitly:

$dotnetBinary = '/mnt/c/Program Files/dotnet/dotnet.exe';
$resolver = new DotnetRuntimeResolver($runner, $dotnetBinary);
$operations = new CsharpCodeOperations($resolver, $runner);

$context = new ExecutionContextDto(
    projectPath: '/mnt/d/Programing/my-project',
    runtime: new RuntimeVo('csharp', null),
);

WSL mode is detected when PHP runs on Linux and the configured executable ends in .exe. In that mode, the library forwards required environment variable names through WSLENV and converts Windows diagnostic paths under drive roots to /mnt/<drive> paths. Projects and working directories used with Windows interop should be on a mounted drive, such as /mnt/d/....

Remote projects

Both DotnetRuntimeResolver and CsharpCodeOperations accept an optional final FileSystemInterface argument for projects stored outside the local machine. Pass a filesystem rooted at the project directory and a CommandRunnerInterface that executes commands in the same remote workspace. The project path is supplied later through ExecutionContextDto; filesystem paths remain relative to its root (. for the project root and global.json for the SDK configuration). Without a filesystem argument, the existing local-disk behavior is unchanged.

$resolver = new DotnetRuntimeResolver($runner, 'dotnet', $remoteFileSystem);
$operations = new CsharpCodeOperations($resolver, $runner, fileSystem: $remoteFileSystem);

SDK selection

DotnetRuntimeResolver reads sdk.version from global.json in the project root. Without that setting it selects the highest installed SDK. Requested versions are matched as prefixes against dotnet --list-sdks; when global.json selects a different SDK, the resolver reports that SDK selection is controlled by global.json.

Integration tests

The default PHPUnit suite includes the csharp integration group. Run that group directly with:

vendor/bin/phpunit --group csharp

The integration test uses DOTNET_BINARY when set, otherwise it looks for dotnet in PATH. If neither is available, PHPUnit marks the integration test skipped. Set CODE_OPERATIONS_TMP to a writable directory when a specific temporary location is required; when using a Windows .exe through WSL, it must be under /mnt/<drive>.