Commit 62f1c38
authored
Replace deprecated ScreenResolutionUtility task with PowerShell script for Windows UI tests (#32599)
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
### Description of Change
The Azure DevOps marketplace task `ScreenResolutionUtility@1` has been
deprecated and removed, blocking Windows UI tests from running with
required screen resolution on new agents.
**Solution**: Custom PowerShell script using Windows API
- **Created** `eng/scripts/Set-ScreenResolution.ps1`
- Uses `ChangeDisplaySettings` Windows API via P/Invoke with proper
DEVMODE structure
- Uses `CharSet = CharSet.Auto` for better cross-platform compatibility
- Correct API signature: `EnumDisplaySettings` returns `bool` instead of
`int`
- Sets `dmFields` to specify which fields are being modified
(DM_PELSWIDTH | DM_PELSHEIGHT)
- **Fallback logic**: If display enumeration fails (common on
headless/virtual agents), continues with a warning and attempts to set
resolution anyway
- Validates resolution support before applying
- Comprehensive error handling with all Windows API error codes
(BADMODE, NOTUPDATED, BADFLAGS, BADPARAM)
- Proper exit codes for pipeline integration
- **Updated** `eng/pipelines/common/ui-tests-steps.yml`
- Replaced deprecated marketplace task with PowerShell script invocation
- Preserved Windows-only conditional logic
- Maintained 1920x1080 resolution for UI tests
**Before:**
```yaml
- task: ScreenResolutionUtility@1
condition: eq('${{ parameters.platform }}' , 'windows')
inputs:
displaySettings: 'specific'
width: '1920'
height: '1080'
```
**After:**
```yaml
- pwsh: |
$scriptPath = Join-Path "$(System.DefaultWorkingDirectory)" "eng" "scripts" "Set-ScreenResolution.ps1"
& $scriptPath -Width 1920 -Height 1080
condition: eq('${{ parameters.platform }}' , 'windows')
```
**Key Improvements**: The script now handles Azure DevOps agents that
may not have traditional display subsystems. It includes fallback logic
to gracefully handle cases where display enumeration fails (returning
false) on headless/virtual agents, while still attempting to set the
resolution. This is essential for CI/CD environments where agents may
not have real displays attached.
### Issues Fixed
Fixes #[issue_number_if_available]
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
> Replace the deprecated Azure DevOps screen resolution utility task
with a custom PowerShell script solution for UITests.
>
> ## Context
> The Azure DevOps marketplace task
`ms-autotest.screen-resolution-utility-task` has been deprecated and
removed, blocking UITests from running with the required screen
resolution configuration on new agents.
>
> ## Previous Usage
> ```yaml
> - task: ScreenResolutionUtility@1
> condition: eq('${{ parameters.platform }}' , 'windows')
> inputs:
> displaySettings: 'specific'
> width: '1920'
> height: '1080'
> displayName: "Set screen resolution"
> ```
>
> ## Solution Requirements
> 1. Create a PowerShell script (`Set-ScreenResolution.ps1`) that can
programmatically set the screen resolution on Windows agents
> 2. The script should:
> - Accept width and height as parameters
> - Set the screen resolution to the specified values (e.g., 1920x1080)
> - Handle errors gracefully with appropriate logging
> - Work on Azure DevOps hosted and self-hosted Windows agents
> - Set the primary display resolution
> 3. Update the CI/CD pipeline YAML files to use the new PowerShell
script instead of the deprecated task
> 4. Replace all instances of `ScreenResolutionUtility@1` task with the
new script approach
> 5. Maintain the same conditional logic (only run on Windows platform)
>
> ## Technical Approach
> The script should use Windows API calls through PowerShell to change
display settings, utilizing the ChangeDisplaySettingsEx function or
similar Windows APIs through Add-Type with C# code.
>
> ## Expected Result
> - A reusable PowerShell script in the repository (suggested location:
`eng/scripts/Set-ScreenResolution.ps1` or similar)
> - Updated pipeline YAML files replacing the deprecated task with
PowerShell script invocation
> - The solution should work identically to the previous task, setting
1920x1080 resolution for UITests on Windows agents
</details>
*This pull request was created as a result of the following prompt from
Copilot chat.*
> Replace the deprecated Azure DevOps screen resolution utility task
with a custom PowerShell script solution for UITests.
>
> ## Context
> The Azure DevOps marketplace task
`ms-autotest.screen-resolution-utility-task` has been deprecated and
removed, blocking UITests from running with the required screen
resolution configuration on new agents.
>
> ## Previous Usage
> ```yaml
> - task: ScreenResolutionUtility@1
> condition: eq('${{ parameters.platform }}' , 'windows')
> inputs:
> displaySettings: 'specific'
> width: '1920'
> height: '1080'
> displayName: "Set screen resolution"
> ```
>
> ## Solution Requirements
> 1. Create a PowerShell script (`Set-ScreenResolution.ps1`) that can
programmatically set the screen resolution on Windows agents
> 2. The script should:
> - Accept width and height as parameters
> - Set the screen resolution to the specified values (e.g., 1920x1080)
> - Handle errors gracefully with appropriate logging
> - Work on Azure DevOps hosted and self-hosted Windows agents
> - Set the primary display resolution
> 3. Update the CI/CD pipeline YAML files to use the new PowerShell
script instead of the deprecated task
> 4. Replace all instances of `ScreenResolutionUtility@1` task with the
new script approach
> 5. Maintain the same conditional logic (only run on Windows platform)
>
> ## Technical Approach
> The script should use Windows API calls through PowerShell to change
display settings, utilizing the ChangeDisplaySettingsEx function or
similar Windows APIs through Add-Type with C# code.
>
> ## Expected Result
> - A reusable PowerShell script in the repository (suggested location:
`eng/scripts/Set-ScreenResolution.ps1` or similar)
> - Updated pipeline YAML files replacing the deprecated task with
PowerShell script invocation
> - The solution should work identically to the previous task, setting
1920x1080 resolution for UITests on Windows agents
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).2 files changed
Lines changed: 242 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
111 | 108 | | |
112 | 109 | | |
113 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
0 commit comments