-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix vs2022 Image rejecting preview sdks, failing to resolve sdks
#51558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nagilson
merged 2 commits into
dotnet:release/9.0.3xx
from
nagilson:nagilson-vs-rejects-previews-903
Nov 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Set sdk.txt file to enable preview SDKs
- VS uses the local appdata, VS versioned folder, sdk.txt file to determine whether or not to accept preview sdks - VS Release rejects preview SDKs by default which causes the msbuild sdk resolver to not find sdks, as msbuild respects the vs settings - This changes the vs settings to enable our internal SDKs to be found by msbuild when it's going under test. - Possible improvements: this PR assumes sdk.txt content ordering does not matter - based on VS code this appears to be true but could change in the future Also tried: - modifying global.json to enable preview sdks, which was not enough. some tests have a custom global.json and it seems to not take precedence setting env vars such as msbuildsdks which did not take precedence over the vs setting This commit is a condensed version of the work done in #51591 and #51598
- Loading branch information
commit 665cdcb18fd9f0b4eed1b93c44efed3820312ebb
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| param() | ||
|
|
||
| . $PSScriptRoot\common\tools.ps1 | ||
|
|
||
| try { | ||
| $vsInfo = LocateVisualStudio | ||
| } | ||
| catch { | ||
| Write-Host "LocateVisualStudio failed: $_" | ||
| return | ||
| } | ||
|
|
||
| if ($null -eq $vsInfo) { | ||
| Write-Host "No Visual Studio instance detected; preview SDKs remain enabled by default." | ||
| return | ||
| } | ||
|
|
||
| $vsId = $vsInfo.instanceId | ||
| $vsMajorVersion = $vsInfo.installationVersion.Split('.')[0] | ||
| $instanceDir = Join-Path $env:USERPROFILE "AppData\Local\Microsoft\VisualStudio\$vsMajorVersion.0_$vsId" | ||
|
|
||
| Create-Directory $instanceDir | ||
|
|
||
| $sdkFile = Join-Path $instanceDir 'sdk.txt' | ||
|
|
||
| $desiredLine = 'UsePreviews=True' | ||
| $existingLines = @() | ||
|
|
||
| if (Test-Path $sdkFile) { | ||
| $existingLines = @(Get-Content -Path $sdkFile -Encoding ASCII) | ||
| } | ||
|
|
||
| # Determine how to place the UsePreviews flag based on existing content. | ||
| $replacementIndex = -1 | ||
| for ($i = 0; $i -lt $existingLines.Count; $i++) { | ||
| if ($existingLines[$i] -match '^UsePreviews=.*$') { | ||
| $replacementIndex = $i | ||
| break | ||
| } | ||
| } | ||
|
|
||
| # Replace the existing line to enforce it as True | ||
| if ($replacementIndex -ge 0) { | ||
| $updatedLines = $existingLines | ||
| $updatedLines[$replacementIndex] = $desiredLine | ||
| } | ||
| elseif ($existingLines.Count -gt 0) { | ||
| # Write to the top of the file but keep the remaining portion (assumption: order does not matter to VS) | ||
| $updatedLines = @($desiredLine) + $existingLines | ||
| } | ||
| else { | ||
| # Write a whole new file | ||
| $updatedLines = @($desiredLine) | ||
| } | ||
|
|
||
| Set-Content -Path $sdkFile -Value $updatedLines -Encoding ASCII | ||
|
|
||
| Write-Host "Updated $sdkFile" | ||
| Get-Content -Path $sdkFile | ForEach-Object { Write-Host " $_" } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.