dotnet/aspnetcore · error · InvalidOperationException

At least one --target or --targets-file argument must be pro

Error message

At least one --target or --targets-file argument must be provided.

What it means

HelixTestRunnerOptions.Parse collects test targets from the --target option (repeatable) and from --targets-file (a file with one target per line). After both are processed, if the combined target list is empty it throws - the runner has nothing to execute. Targets are whitespace-trimmed and empty lines are filtered.

Source

Thrown at eng/tools/HelixTestRunner/HelixTestRunnerOptions.cs:86

        var sharedFxVersion = parseResult.ValueForOption<string>("--runtime");
        var targets = new List<string>();
        var commandLineTargets = parseResult.ValueForOption<string[]>("--target");
        if (commandLineTargets is not null)
        {
            targets.AddRange(commandLineTargets.Where(target => !string.IsNullOrWhiteSpace(target)));
        }

        var targetsFile = parseResult.ValueForOption<string>("--targets-file");
        if (!string.IsNullOrWhiteSpace(targetsFile))
        {
            targets.AddRange(File.ReadLines(targetsFile)
                .Select(line => line.Trim())
                .Where(line => !string.IsNullOrWhiteSpace(line)));
        }

        if (targets.Count == 0)
        {
            throw new InvalidOperationException("At least one --target or --targets-file argument must be provided.");
        }

        var options = new HelixTestRunnerOptions
        {
            Architecture = parseResult.ValueForOption<string>("--arch"),
            HelixQueue = parseResult.ValueForOption<string>("--queue"),
            InstallPlaywright = parseResult.ValueForOption<bool>("--playwright"),
            Quarantined = parseResult.ValueForOption<bool>("--quarantined"),
            RuntimeVersion = sharedFxVersion,
            Targets = targets.ToArray(),
            TargetsFile = targetsFile,
            Timeout = TimeSpan.Parse(parseResult.ValueForOption<string>("--helixTimeout"), CultureInfo.InvariantCulture),

            // When targeting pack builds, it has exactly the same version as the shared framework.
            AspNetRef = $"Microsoft.AspNetCore.App.Ref.{sharedFxVersion}.nupkg",
            AspNetRuntime = $"Microsoft.AspNetCore.App.Runtime.win-x64.{sharedFxVersion}.nupkg",

            DotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT"),

View on GitHub (pinned to 3600ca084e)

Solutions

  1. Pass at least one --target <name> on the command line, or a non-empty --targets-file <path>.
  2. Verify the targets-file exists and has at least one non-blank line.
  3. In the job definition, ensure the property feeding targets is set before the runner executes.

Example fix

// before
dotnet HelixTestRunner.dll --runtime 8.0.0 --arch x64
// after
dotnet HelixTestRunner.dll --runtime 8.0.0 --arch x64 --target src/Tests/MyTests.csproj
Defensive patterns

Strategy: validation

Validate before calling

if (targets.Count == 0) {
    Console.Error.WriteLine("Pass --target <csproj> or --targets-file <path> with at least one non-blank line.");
    return 2;
}

Type guard

static bool HasTargets(IReadOnlyCollection<string> t) => t != null && t.Count > 0;

Try / catch

try {
    var opts = HelixTestRunnerOptions.Parse(args);
} catch (InvalidOperationException ex) when (ex.Message.Contains("--target")) {
    // fix the invocation: add --target or a non-empty --targets-file
    Console.Error.WriteLine(ex.Message);
    return 2;
}

Prevention

When it happens

Trigger: Invoking HelixTestRunner with neither --target nor --targets-file, or with a --targets-file that is empty/contains only blank lines, or with --target values that are all whitespace (HelixTestRunnerOptions.cs:70-87).

Common situations: A CI/helix job template omitted the target argument; the targets-file path was wrong so no targets loaded; the helix work item payload did not propagate the target list.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/01b732b5d3a83efe. Report an issue: GitHub.