Add workaround for SDK root drive casing issue#17002
Draft
ViktorHofer wants to merge 10 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Windows-specific workaround in Arcade SDK MSBuild targets to normalize $(NetCoreSdkRoot) drive-letter casing early in the build, mitigating task-host handshake failures caused by casing-sensitive salt computation.
Changes:
- Adds
InitialTargets="NormalizeNetCoreSdkRootCasing"to ensure normalization runs at the start of each project build. - Introduces an inline
RoslynCodeTaskFactorytask that probes canonical drive-letter casing viaLoadLibraryExW+GetModuleFileNameWand rewrites only the drive letter. - Adds a
NormalizeNetCoreSdkRootCasingtarget that updates theNetCoreSdkRootproperty on Windows.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.targets | Adds a new Windows-only target + inline task to normalize NetCoreSdkRoot drive casing and wires it via InitialTargets. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 3
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The previous LoadLibraryEx(LOAD_LIBRARY_AS_DATAFILE)+GetModuleFileName(hModule) technique was a silent no-op: GetModuleFileName returns ERROR_MOD_NOT_FOUND for an image loaded only as a data file (the SDK's MSBuild.exe/MSBuild.dll are not otherwise loaded in the VS MSBuild process), so the casing was never fixed and MSB4216 persisted (verified in build 2998220). Open the SDK root directory with CreateFileW(FILE_FLAG_BACKUP_SEMANTICS) and ask the OS for its canonical path via GetFinalPathNameByHandleW. This is load- and bitness-independent. Splice only the canonical drive letter, and only when the rest of the path is otherwise case-insensitively identical, so symlink/junction resolution (which GetFinalPathNameByHandle performs but the child's Environment.ProcessPath does not) cannot desync the two salts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the temporary #14026 workaround leave visible evidence in CI console logs (it only fires when the drive casing actually differs, so this is not noisy on healthy machines). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines
+325
to
+334
| // Open the SDK root directory (FILE_FLAG_BACKUP_SEMANTICS is required to get a | ||
| // handle to a directory). We need no access rights for GetFinalPathNameByHandle. | ||
| IntPtr handle = CreateFileW( | ||
| SdkRoot, | ||
| 0, | ||
| FILE_SHARE_READ_WRITE_DELETE, | ||
| IntPtr.Zero, | ||
| OPEN_EXISTING, | ||
| FILE_FLAG_BACKUP_SEMANTICS, | ||
| IntPtr.Zero); |
Comment on lines
+372
to
+380
| // Only adopt the canonical drive letter when the rest of the path is | ||
| // otherwise identical (case-insensitively). This rejects any structural | ||
| // change from symlink/junction resolution, which GetFinalPathNameByHandle | ||
| // performs but the child's Environment.ProcessPath (GetModuleFileNameW) | ||
| // does not - keeping both sides' salts in agreement. | ||
| if (canonical.Length >= 2 && canonical[1] == ':' && | ||
| string.Equals(canonical, SdkRoot, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| char canonicalDrive = canonical[0]; |
NetCoreSdkRoot carries a trailing directory separator, but GetFinalPathNameByHandle returns the canonical path without one. The strict full-path equality guard therefore always failed, making the drive-casing normalization a silent no-op and leaving MSB4216 (#14026) unfixed. Compare with trailing separators trimmed from both sides. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To double check: