Commit 673ef31
Fix macOS symlink handshake mismatch in .NET task host (MSB4216) (dotnet#13406)
### Context
PR dotnet#13175 (App Host Support) introduced a regression on macOS when the
SDK is accessed through a symlinked path. On macOS, `/tmp` is a symlink
to `/private/tmp`. When Helix tests run from `/tmp/helix/...`, the
`$(NetCoreSdkRoot)` MSBuild property preserves the unresolved path
`/tmp/helix/.../sdk/11.0.100-ci`, but the child task host process
resolves it to `/private/tmp/helix/.../sdk/11.0.100-ci` via
`AppContext.BaseDirectory`.
### Root Cause
In `ResolveAppHostOrFallback`, the parent passed `toolsDirectory:
msbuildAssemblyPath` (from `$(NetCoreSdkRoot)`) to the `Handshake`
constructor, while the child (`NodeEndpointOutOfProcTaskHost`) passed no
explicit `toolsDirectory`, defaulting to
`BuildEnvironmentHelper.Instance.MSBuildToolsDirectoryRoot` (which
resolves symlinks).
This produced different handshake hashes:
- **Parent**: `hash("/tmp/.../sdk/11.0.100-ci")`
- **Child**: `hash("/private/tmp/.../sdk/11.0.100-ci")`
- **Result**: Handshake mismatch -> MSB4216
Before PR dotnet#13175, neither side passed explicit `toolsDirectory`, so both
defaulted to `BuildEnvironmentHelper` and always matched.
### Changes Made
- On .NET Core (`#if RUNTIME_TYPE_NETCORE`): omit explicit
`toolsDirectory` so both parent and child default to
`BuildEnvironmentHelper.Instance.MSBuildToolsDirectoryRoot`, which
resolves symlinks consistently via `AppContext.BaseDirectory`.
- On .NET Framework: keep `toolsDirectory: msbuildAssemblyPath` because
the parent (VS) and child (.NET task host) are in **different
directories**, and Windows has no symlink issues.
- Updated regression test to validate actual fix behavior (not
tautological).
### Testing
- `Handshake_ExternalPathCanMismatch_DefaultAlwaysMatches` - proves that
an external path (like `$(NetCoreSdkRoot)`) produces a different
handshake than the default, and that omitting `toolsDirectory` on both
sides always matches.
- `Handshake_WithSymlinkedToolsDirectory_ProducesDifferentKey` - proves
the bug mechanism with real symlinks on Unix.
- Existing E2E tests for TaskHostFactory tasks.
- SDK test validation on Helix macOS (the original failing environment).
### Notes
This fix addresses the MSB4216 errors seen in SDK Helix tests for
`ComputeWasmBuildAssets`, `ComputeManagedAssemblies`,
`MarshalingPInvokeScanner`, and other `TaskHostFactory` tasks on macOS.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 8d5ad98 commit 673ef31
3 files changed
Lines changed: 215 additions & 2 deletions
File tree
- src
- Build.UnitTests
- BackEnd
- Build/BackEnd/Components/Communications
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
155 | 156 | | |
156 | 157 | | |
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 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
158 | 277 | | |
159 | 278 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
274 | 275 | | |
275 | 276 | | |
276 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
277 | 352 | | |
278 | 353 | | |
Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
733 | 733 | | |
734 | 734 | | |
735 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
736 | 755 | | |
737 | 756 | | |
738 | 757 | | |
| |||
744 | 763 | | |
745 | 764 | | |
746 | 765 | | |
747 | | - | |
| 766 | + | |
748 | 767 | | |
749 | 768 | | |
750 | 769 | | |
| |||
762 | 781 | | |
763 | 782 | | |
764 | 783 | | |
765 | | - | |
| 784 | + | |
766 | 785 | | |
767 | 786 | | |
768 | 787 | | |
| |||
0 commit comments