|
3 | 3 |
|
4 | 4 | <# |
5 | 5 | .SYNOPSIS |
6 | | - Generates a filtered .slnx solution file that only includes test projects supporting a given target framework. |
| 6 | + Generates a filtered .slnx solution file by removing projects that don't match the specified criteria. |
7 | 7 |
|
8 | 8 | .DESCRIPTION |
9 | | - Parses a .slnx solution file and queries each test project's TargetFrameworks using MSBuild. |
10 | | - Removes test projects that don't support the specified target framework, writes the result |
11 | | - to a temporary or specified output path, and prints the output path. |
12 | | -
|
13 | | - This is useful for running `dotnet test --solution` with MTP (Microsoft Testing Platform), |
14 | | - which requires all test projects in the solution to support the requested target framework. |
| 9 | + Parses a .slnx solution file and applies one or more filters: |
| 10 | + - Removes projects that don't support the specified target framework (via MSBuild query). |
| 11 | + - Optionally removes all sample projects (under samples/). |
| 12 | + - Optionally filters test projects by name pattern (e.g., only *UnitTests*). |
| 13 | + Writes the filtered solution to the specified output path and prints the path. |
15 | 14 |
|
16 | 15 | .PARAMETER Solution |
17 | 16 | Path to the source .slnx solution file. |
|
34 | 33 |
|
35 | 34 | .EXAMPLE |
36 | 35 | # Generate a filtered solution and run tests |
37 | | - $filtered = ./eng/New-FilteredSolution.ps1 -Solution ./agent-framework-dotnet.slnx -TargetFramework net472 |
| 36 | + $filtered = .github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net472 |
38 | 37 | dotnet test --solution $filtered --no-build -f net472 |
39 | 38 |
|
40 | 39 | .EXAMPLE |
41 | 40 | # Generate a solution with only unit test projects |
42 | | - ./eng/New-FilteredSolution.ps1 -Solution ./agent-framework-dotnet.slnx -TargetFramework net10.0 -TestProjectNameFilter "*UnitTests*" -OutputPath filtered-unit.slnx |
| 41 | + .github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net10.0 -TestProjectNameFilter "*UnitTests*" -OutputPath filtered-unit.slnx |
43 | 42 |
|
44 | 43 | .EXAMPLE |
45 | 44 | # Inline usage with dotnet test (PowerShell) |
46 | | - dotnet test --solution (./eng/New-FilteredSolution.ps1 -Solution ./agent-framework-dotnet.slnx -TargetFramework net472) --no-build -f net472 |
| 45 | + dotnet test --solution (.github/workflows/New-FilteredSolution.ps1 -Solution dotnet/agent-framework-dotnet.slnx -TargetFramework net472) --no-build -f net472 |
47 | 46 | #> |
48 | 47 |
|
49 | 48 | [CmdletBinding()] |
@@ -91,16 +90,17 @@ if ($ExcludeSamples) { |
91 | 90 | Write-Host "Removed $($sampleProjects.Count) sample project(s)." -ForegroundColor Yellow |
92 | 91 | } |
93 | 92 |
|
94 | | -# Find all Project elements with paths containing "tests/" |
95 | | -$testProjects = $slnx.SelectNodes("//Project[contains(@Path, 'tests/')]") |
| 93 | +# Filter all remaining projects by target framework |
| 94 | +$allProjects = $slnx.SelectNodes("//Project") |
96 | 95 |
|
97 | | -foreach ($proj in $testProjects) { |
| 96 | +foreach ($proj in $allProjects) { |
98 | 97 | $projRelPath = $proj.GetAttribute("Path") |
99 | 98 | $projFullPath = Join-Path $solutionDir $projRelPath |
100 | 99 | $projFileName = Split-Path $projRelPath -Leaf |
| 100 | + $isTestProject = $projRelPath -like "*tests/*" |
101 | 101 |
|
102 | | - # Filter by project name pattern if specified |
103 | | - if ($TestProjectNameFilter -and ($projFileName -notlike $TestProjectNameFilter)) { |
| 102 | + # Filter test projects by name pattern if specified |
| 103 | + if ($isTestProject -and $TestProjectNameFilter -and ($projFileName -notlike $TestProjectNameFilter)) { |
104 | 104 | Write-Verbose "Removing (name filter): $projRelPath" |
105 | 105 | $removed += $projRelPath |
106 | 106 | $proj.ParentNode.RemoveChild($proj) | Out-Null |
@@ -139,7 +139,7 @@ if ($removed.Count -gt 0) { |
139 | 139 | Write-Host " - $r" -ForegroundColor Yellow |
140 | 140 | } |
141 | 141 | } |
142 | | -Write-Host "Kept $($kept.Count) test project(s)." -ForegroundColor Green |
| 142 | +Write-Host "Kept $($kept.Count) project(s)." -ForegroundColor Green |
143 | 143 |
|
144 | 144 | # Output the path for piping |
145 | 145 | Write-Output $OutputPath |
0 commit comments