Skip to content

Add Project/Solution flags to DotNet.TestOptions for SDK 10+ support#2897

Draft
bartelink wants to merge 1 commit into
fsprojects:masterfrom
bartelink:add-project-solution-to-TestOptions
Draft

Add Project/Solution flags to DotNet.TestOptions for SDK 10+ support#2897
bartelink wants to merge 1 commit into
fsprojects:masterfrom
bartelink:add-project-solution-to-TestOptions

Conversation

@bartelink

@bartelink bartelink commented May 30, 2026

Copy link
Copy Markdown
Member

Hm, my agent jumped the gun on actually raising a PR but here we are...
Still need to figure out whether mutually exclusive option args are idiomatic for FAKE.
Also it appears that --project project.slnx just works, so maybe a different approach is possible.
Using a workaround in Argu until I get comments on this; it's not urgent from my perspective...


Problem

SDK 10 no longer accepts a positional project/solution path for dotnet test. The argument must be passed via --project or --solution flags:

dotnet test tests/MyProject.Tests.fsproj  # ❌ SDK 10: exit code 1
dotnet test --project tests/MyProject.Tests.fsproj  # ✅

Users migrating to Microsoft.Testing.Platform v2 with SDK 10 face an additional issue: MTP v2 crashes (IndexOutOfRangeException, exit code 134) if an empty string is passed as an argument. This means the current workaround of passing "" as the project with --project in CustomParams fails.

Fix

  • Add Project: string option--project flag
  • Add Solution: string option--solution flag
  • Skip the positional arg when project is empty (allows DotNet.test id "" + Project = Some path)

Usage (SDK 10 + MTP v2)

DotNet.test (fun c ->
    { c with
        Project = Some "tests/MyProject.Tests.fsproj"
        NoBuild = true
        Configuration = DotNet.BuildConfiguration.Release }) ""

Backward compatibility

No breaking change — existing callers passing a positional path continue to work unchanged. The Project/Solution fields default to None.

SDK 10 no longer accepts positional project/solution args for 'dotnet test'.
Instead, '--project' or '--solution' flags must be used.

This adds:
- Project: string option → --project flag
- Solution: string option → --solution flag
- Filters empty positional 'project' arg from the command (avoids crash
  when using Project/Solution fields with empty string as positional arg)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 30, 2026 14:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for the new dotnet test targeting flags introduced in newer SDKs by allowing --project / --solution to be passed via TestOptions, and avoids emitting an empty positional project argument.

Changes:

  • Extend TestOptions with Project and Solution optional fields and defaults.
  • Include --project / --solution in dotnet test argument construction.
  • Stop passing an empty positional project argument to dotnet test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1851 to +1852
let positionalArg = if String.IsNullOrEmpty project then [] else [ project ]
let args = positionalArg @ buildTestArgs param

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see preamble in OP)

use __ = Trace.traceTask "DotNet:test" project
let param = TestOptions.Create() |> setParams
let args = project :: buildTestArgs param
let positionalArg = if String.IsNullOrEmpty project then [] else [ project ]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also doesnt use solution arg - probably needs to be mutually exclusive and added at end after positional args

@bartelink bartelink marked this pull request as draft May 30, 2026 14:48
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

   12 files  + 2     12 suites  +2   27m 37s ⏱️ + 11m 22s
  452 tests ± 0    451 ✅ + 1  1 💤 ±0  0 ❌  - 1 
1 290 runs  +84  1 287 ✅ +85  3 💤 ±0  0 ❌  - 1 

Results for commit 9ca3eb5. ± Comparison against base commit e37773e.

@@ -1766,6 +1766,16 @@ module DotNet =
/// order of tests execution before the crash. (<c>--blame</c>)
Blame: bool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs comment to mention it doesnt work for MTP anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants