Commit 5048a76
committed
[dotnet-run] implement "device" selection logic
Context: https://github.com/dotnet/sdk/blob/5398e10de90dc9a27e0290ad55c2ae67360ea8be/documentation/specs/dotnet-run-for-maui.md
~~ Spec Changes ~~
**Added RuntimeIdentifier Support**
- Examples to include `%(RuntimeIdentifier)` metadata
(e.g., `android-arm64`, `ios-arm64`, `iossimulator-arm64`)
- When a device provides a `%(RuntimeIdentifier)`, it will be passed
as `-p:RuntimeIdentifier` to subsequent MSBuild steps (build,
deploy, ComputeRunArguments, run)
- `%(RuntimeIdentifier)` is optional but recommended
**Added Binary Logs Documentation**
- Added new section "Binary Logs for Device Selection" explaining:
- When binlog files are created (when using `-bl:` with `dotnet run`)
- The naming pattern: `<base-name>-dotnet-run-devices.binlog`
~~ Implementation ~~
**Renamed `TargetFrameworkSelector` to `RunCommandSelector`**
- Expanded scope from just framework selection to handle both target
framework and device selection
- Made it a non-static class implementing `IDisposable` to:
- Cache the MSBuild project instance across operations
- Avoid loading/evaluating the project multiple times, except when
global properties change
- Properly manage MSBuild resources (ProjectCollection, Project,
ProjectInstance) with `IDisposable`
- Added `InvalidateGlobalProperties()` method to re-evaluate the
project when needed with a `$(TargetFramework)` global property change.
- Binary logger is owned by the `selector` instance and properly
disposed.
**Added Tests**
- Mock test project (`DotnetRunDevices.csproj`) implements
`ComputeAvailableDevices` target that returns hardcoded device items
based on the target framework
- Test project includes `GenerateDeviceInfo` target that runs during
build when a device is selected:
- Generates `DeviceInfo.cs` with constants for `$(Device)` and
`$(RuntimeIdentifier)` properties
- Writes to intermediate output directory before compilation
- Test application prints these generated constants, allowing tests to
verify that:
- The correct device ID was passed to MSBuild
- `$(RuntimeIdentifier)` was propagated correctly (when provided by device)
- Multi-targeted apps can have different devices per framework1 parent 6756697 commit 5048a76
File tree
24 files changed
+1488
-174
lines changed- documentation/specs
- src/Cli
- Microsoft.DotNet.Cli.Utils
- dotnet/Commands
- Run
- Api
- xlf
- test
- TestAssets/TestProjects/DotnetRunDevices
- dotnet.Tests/CommandTests/Run
24 files changed
+1488
-174
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
84 | | - | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | | - | |
| 96 | + | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
97 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
101 | | - | |
| 108 | + | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
| |||
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
142 | 162 | | |
143 | 163 | | |
144 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1786 | 1786 | | |
1787 | 1787 | | |
1788 | 1788 | | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
1789 | 1813 | | |
1790 | 1814 | | |
1791 | 1815 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
88 | 98 | | |
89 | 99 | | |
90 | 100 | | |
| |||
93 | 103 | | |
94 | 104 | | |
95 | 105 | | |
| 106 | + | |
| 107 | + | |
96 | 108 | | |
97 | 109 | | |
98 | 110 | | |
| |||
112 | 124 | | |
113 | 125 | | |
114 | 126 | | |
| 127 | + | |
| 128 | + | |
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
| |||
128 | 142 | | |
129 | 143 | | |
130 | 144 | | |
131 | | - | |
132 | | - | |
| 145 | + | |
| 146 | + | |
133 | 147 | | |
134 | | - | |
| 148 | + | |
| 149 | + | |
135 | 150 | | |
136 | 151 | | |
137 | 152 | | |
| |||
199 | 214 | | |
200 | 215 | | |
201 | 216 | | |
202 | | - | |
203 | | - | |
204 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
205 | 220 | | |
206 | 221 | | |
207 | | - | |
| 222 | + | |
208 | 223 | | |
209 | 224 | | |
210 | 225 | | |
211 | 226 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
217 | 259 | | |
218 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
219 | 271 | | |
220 | 272 | | |
221 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
222 | 299 | | |
223 | 300 | | |
224 | 301 | | |
| |||
246 | 323 | | |
247 | 324 | | |
248 | 325 | | |
249 | | - | |
250 | | - | |
| 326 | + | |
| 327 | + | |
251 | 328 | | |
252 | 329 | | |
253 | 330 | | |
| |||
805 | 882 | | |
806 | 883 | | |
807 | 884 | | |
| 885 | + | |
| 886 | + | |
808 | 887 | | |
809 | 888 | | |
810 | 889 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
51 | 63 | | |
52 | 64 | | |
53 | 65 | | |
| |||
98 | 110 | | |
99 | 111 | | |
100 | 112 | | |
| 113 | + | |
| 114 | + | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
| |||
0 commit comments