{"record":{"id":"01b732b5d3a83efe","repo":"dotnet/aspnetcore","slug":"at-least-one-target-or-targets-file-argument-m","errorCode":null,"errorMessage":"At least one --target or --targets-file argument must be provided.","messagePattern":"At least one --target or --targets-file argument must be provided\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"eng/tools/HelixTestRunner/HelixTestRunnerOptions.cs","lineNumber":86,"sourceCode":"        var sharedFxVersion = parseResult.ValueForOption<string>(\"--runtime\");\n        var targets = new List<string>();\n        var commandLineTargets = parseResult.ValueForOption<string[]>(\"--target\");\n        if (commandLineTargets is not null)\n        {\n            targets.AddRange(commandLineTargets.Where(target => !string.IsNullOrWhiteSpace(target)));\n        }\n\n        var targetsFile = parseResult.ValueForOption<string>(\"--targets-file\");\n        if (!string.IsNullOrWhiteSpace(targetsFile))\n        {\n            targets.AddRange(File.ReadLines(targetsFile)\n                .Select(line => line.Trim())\n                .Where(line => !string.IsNullOrWhiteSpace(line)));\n        }\n\n        if (targets.Count == 0)\n        {\n            throw new InvalidOperationException(\"At least one --target or --targets-file argument must be provided.\");\n        }\n\n        var options = new HelixTestRunnerOptions\n        {\n            Architecture = parseResult.ValueForOption<string>(\"--arch\"),\n            HelixQueue = parseResult.ValueForOption<string>(\"--queue\"),\n            InstallPlaywright = parseResult.ValueForOption<bool>(\"--playwright\"),\n            Quarantined = parseResult.ValueForOption<bool>(\"--quarantined\"),\n            RuntimeVersion = sharedFxVersion,\n            Targets = targets.ToArray(),\n            TargetsFile = targetsFile,\n            Timeout = TimeSpan.Parse(parseResult.ValueForOption<string>(\"--helixTimeout\"), CultureInfo.InvariantCulture),\n\n            // When targeting pack builds, it has exactly the same version as the shared framework.\n            AspNetRef = $\"Microsoft.AspNetCore.App.Ref.{sharedFxVersion}.nupkg\",\n            AspNetRuntime = $\"Microsoft.AspNetCore.App.Runtime.win-x64.{sharedFxVersion}.nupkg\",\n\n            DotnetRoot = Environment.GetEnvironmentVariable(\"DOTNET_ROOT\"),","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/eng/tools/HelixTestRunner/HelixTestRunnerOptions.cs#L68-L104","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass at least one --target <name> on the command line, or a non-empty --targets-file <path>.","Verify the targets-file exists and has at least one non-blank line.","In the job definition, ensure the property feeding targets is set before the runner executes."],"exampleFix":"// before\ndotnet HelixTestRunner.dll --runtime 8.0.0 --arch x64\n// after\ndotnet HelixTestRunner.dll --runtime 8.0.0 --arch x64 --target src/Tests/MyTests.csproj","handlingStrategy":"validation","validationCode":"if (targets.Count == 0) {\n    Console.Error.WriteLine(\"Pass --target <csproj> or --targets-file <path> with at least one non-blank line.\");\n    return 2;\n}","typeGuard":"static bool HasTargets(IReadOnlyCollection<string> t) => t != null && t.Count > 0;","tryCatchPattern":"try {\n    var opts = HelixTestRunnerOptions.Parse(args);\n} catch (InvalidOperationException ex) when (ex.Message.Contains(\"--target\")) {\n    // fix the invocation: add --target or a non-empty --targets-file\n    Console.Error.WriteLine(ex.Message);\n    return 2;\n}","preventionTips":["Always pass at least one --target or a populated --targets-file.","Validate the targets-file exists and is non-empty before the runner starts.","Echo the resolved target count in the job log for fast diagnosis."],"tags":["csharp","dotnet","testing","helix","cli","arguments"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}