Solve .NET SDK version check failure when building PowerShell.#17203
Solve .NET SDK version check failure when building PowerShell.#17203Fragmachine wants to merge 2 commits intoPowerShell:masterfrom
Conversation
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
|
|
@Fragmachine I guess changes here can be superseded by #17198, right? |
|
@daxian-dbw Yes, I've already talked to @powercode about it (we work at the same company). He solved the first issue I ran into but then I hit this other case with the SDK not being in the order the build script expected. |
|
@Fragmachine So you mean this PR should supersede @powercode's #17198 then?
#17198 fixes the parsing, and also sort the results to get the highest version. I presume that resolves the other issue you ran into, right? |
|
Yes, this supersedes #17198. The reason being that 'Get-LatestInstalledSDK' indeed returns the latest which doesn't work if you have an SDK installed that's newer than the required. Essentially, there's a time gap between a new SDK version being released and PowerShell being updated to use it (I assume the intention is to stay close to the latest). |
I believe that is intentional, because we want to make sure the exact version defined in global.json is used for the building. If you are fine taking the risk for a private build to use a newer SDK, then you should just update the sdk version in |
|
You misunderstand, this is not about building against another SDK older or newer. It's about being able to build with the appropriate SDK while having the others installed as well. As long as the correct version has priority i.e. the first one in PATH it works as it should. |
|
Understood. Your change is basically to make sure the SDK with desired version can be found first from the path. |
| function Get-DotNetVersionInPath { | ||
| Start-NativeExecution -sb { | ||
| dotnet --list-sdks | Select-String -Pattern '\d*.\d*.\d*(-\w*\.\d*.\d*.\d*)?' | ForEach-Object { [System.Management.Automation.SemanticVersion]::new($_.matches.value) } | Sort-Object -Descending | Select-Object -First 1 | ||
| dotnet --version |
There was a problem hiding this comment.
I don't think this will work. When running within the repo folder, global.json will be honored, so dotnet --version will returns messages like the following when the dotnet version doesn't match:
PS:15> dotnet --version
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application '--version' does not exist.
* You intended to execute a .NET SDK command:
A compatible installed .NET SDK for global.json version [7.0.100-preview.2.22153.17] from [C:\arena\source\PowerShell\global.json] was not found.
Install the [7.0.100-preview.2.22153.17] .NET SDK or update [C:\arena\source\PowerShell\global.json] with an installed .NET SDK:
5.0.402 [C:\Program Files\dotnet\sdk]
6.0.202 [C:\Program Files\dotnet\sdk]
There was a problem hiding this comment.
I'm afraid we still need dotnet --list-sdks, but instead of returning the highest version, we need to check if the returned versions contain the required version. So, I think part of the changes in #17198 that fixed the parsing is still needed.
|
Superseded by #17299 |
PR Summary
PowerShell fail to build even when the correct .NET SDK version is installed.
PR Context
There are two issues with how the .NET SDK version check works,
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).