diff --git a/.github/workflows/New-FrameworkFilteredSolution.ps1 b/.github/workflows/New-FilteredSolution.ps1 similarity index 73% rename from .github/workflows/New-FrameworkFilteredSolution.ps1 rename to .github/workflows/New-FilteredSolution.ps1 index 3302a0391d..2871f5f36b 100644 --- a/.github/workflows/New-FrameworkFilteredSolution.ps1 +++ b/.github/workflows/New-FilteredSolution.ps1 @@ -3,15 +3,14 @@ <# .SYNOPSIS - Generates a filtered .slnx solution file that only includes test projects supporting a given target framework. + Generates a filtered .slnx solution file by removing projects that don't match the specified criteria. .DESCRIPTION - Parses a .slnx solution file and queries each test project's TargetFrameworks using MSBuild. - Removes test projects that don't support the specified target framework, writes the result - to a temporary or specified output path, and prints the output path. - - This is useful for running `dotnet test --solution` with MTP (Microsoft Testing Platform), - which requires all test projects in the solution to support the requested target framework. + Parses a .slnx solution file and applies one or more filters: + - Removes projects that don't support the specified target framework (via MSBuild query). + - Optionally removes all sample projects (under samples/). + - Optionally filters test projects by name pattern (e.g., only *UnitTests*). + Writes the filtered solution to the specified output path and prints the path. .PARAMETER Solution Path to the source .slnx solution file. @@ -34,16 +33,16 @@ .EXAMPLE # Generate a filtered solution and run tests - $filtered = ./eng/New-FilteredSolution.ps1 -Solution ./agent-framework-dotnet.slnx -TargetFramework net472 + $filtered = .github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net472 dotnet test --solution $filtered --no-build -f net472 .EXAMPLE # Generate a solution with only unit test projects - ./eng/New-FilteredSolution.ps1 -Solution ./agent-framework-dotnet.slnx -TargetFramework net10.0 -TestProjectNameFilter "*UnitTests*" -OutputPath filtered-unit.slnx + .github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net10.0 -TestProjectNameFilter "*UnitTests*" -OutputPath filtered-unit.slnx .EXAMPLE # Inline usage with dotnet test (PowerShell) - dotnet test --solution (./eng/New-FilteredSolution.ps1 -Solution ./agent-framework-dotnet.slnx -TargetFramework net472) --no-build -f net472 + dotnet test --solution (.github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net472) --no-build -f net472 #> [CmdletBinding()] @@ -91,16 +90,17 @@ if ($ExcludeSamples) { Write-Host "Removed $($sampleProjects.Count) sample project(s)." -ForegroundColor Yellow } -# Find all Project elements with paths containing "tests/" -$testProjects = $slnx.SelectNodes("//Project[contains(@Path, 'tests/')]") +# Filter all remaining projects by target framework +$allProjects = $slnx.SelectNodes("//Project") -foreach ($proj in $testProjects) { +foreach ($proj in $allProjects) { $projRelPath = $proj.GetAttribute("Path") $projFullPath = Join-Path $solutionDir $projRelPath $projFileName = Split-Path $projRelPath -Leaf + $isTestProject = $projRelPath -like "*tests/*" - # Filter by project name pattern if specified - if ($TestProjectNameFilter -and ($projFileName -notlike $TestProjectNameFilter)) { + # Filter test projects by name pattern if specified + if ($isTestProject -and $TestProjectNameFilter -and ($projFileName -notlike $TestProjectNameFilter)) { Write-Verbose "Removing (name filter): $projRelPath" $removed += $projRelPath $proj.ParentNode.RemoveChild($proj) | Out-Null @@ -139,7 +139,7 @@ if ($removed.Count -gt 0) { Write-Host " - $r" -ForegroundColor Yellow } } -Write-Host "Kept $($kept.Count) test project(s)." -ForegroundColor Green +Write-Host "Kept $($kept.Count) project(s)." -ForegroundColor Green # Output the path for piping Write-Output $OutputPath diff --git a/.github/workflows/dotnet-build-and-test.yml b/.github/workflows/dotnet-build-and-test.yml index 9899b6ee2e..e79ff15f6d 100644 --- a/.github/workflows/dotnet-build-and-test.yml +++ b/.github/workflows/dotnet-build-and-test.yml @@ -172,7 +172,7 @@ jobs: - name: Generate test solution (no samples) shell: pwsh run: | - .github/workflows/New-FrameworkFilteredSolution.ps1 ` + .github/workflows/New-FilteredSolution.ps1 ` -Solution dotnet/agent-framework-dotnet.slnx ` -TargetFramework ${{ matrix.targetFramework }} ` -Configuration ${{ matrix.configuration }} ` @@ -193,10 +193,10 @@ jobs: Configuration = "${{ matrix.configuration }}" Verbose = $true } - .github/workflows/New-FrameworkFilteredSolution.ps1 @commonArgs ` + .github/workflows/New-FilteredSolution.ps1 @commonArgs ` -TestProjectNameFilter "*UnitTests*" ` -OutputPath dotnet/filtered-unit.slnx - .github/workflows/New-FrameworkFilteredSolution.ps1 @commonArgs ` + .github/workflows/New-FilteredSolution.ps1 @commonArgs ` -TestProjectNameFilter "*IntegrationTests*" ` -OutputPath dotnet/filtered-integration.slnx diff --git a/dotnet/.github/skills/build-and-test/SKILL.md b/dotnet/.github/skills/build-and-test/SKILL.md index a1d57ee3cd..ef04bb96d6 100644 --- a/dotnet/.github/skills/build-and-test/SKILL.md +++ b/dotnet/.github/skills/build-and-test/SKILL.md @@ -101,7 +101,18 @@ Tests use the [Microsoft Testing Platform](https://learn.microsoft.com/dotnet/co ```bash # Run all unit tests across the solution, ignoring projects with no matching tests -dotnet test --solution ./agent-framework-dotnet.slnx --no-build -f net10.0 +dotnet test --solution ./agent-framework-dotnet.slnx --no-build -f net10.0 --ignore-exit-code 8 +``` + +- **Running tests with `--solution` for a specific TFM** requires all projects in the solution to support that TFM. Not all projects target every framework (e.g., some are `net10.0`-only). Use `.github/workflows/New-FilteredSolution.ps1` to generate a filtered solution: + +```powershell +# Generate a filtered solution for net472 and run tests +$filtered = .github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net472 +dotnet test --solution $filtered --no-build -f net472 --ignore-exit-code 8 + +# Exclude samples and keep only unit test projects +.github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net10.0 -ExcludeSamples -TestProjectNameFilter "*UnitTests*" -OutputPath dotnet/filtered-unit.slnx ``` ```bash