Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

When SDK resolution fails because Visual Studio is configured to disallow preview SDKs, users see a generic "Unable to locate the .NET SDK" error even when a preview SDK is installed. This commonly occurs in Azure DevOps with VS 2022 installed.

Changes

Error messaging: Added UnableToLocateNETCoreSdkButPreviewAvailable resource string that reports:

  • The specific preview SDK version available
  • How to enable in VS: Tools → Options → Environment → Preview Features → "Use previews of the .NET SDK"
  • Alternative: "allowPrerelease": true in global.json

SDK resolution retry logic (MSBuildSdkResolver.cs):

  • On resolution failure in VS with previews disallowed, retry with previews allowed
  • If preview SDK found, emit the specific error instead of generic message
  • Wrapped in #if NETFRAMEWORK - only applies to VS on Windows

API extension (NETCoreSdkResolver.cs):

  • Added overload to ResolveNETCoreSdkDirectory accepting explicit disallowPrerelease parameter
  • Preserves existing behavior through parameter defaulting

Tests: Three scenarios covering VS with previews blocked, non-VS environment, and previews already allowed.

Example

Before:

Unable to locate the .NET SDK. Check that it is installed, your PATH is configured for the correct architecture...

After:

Unable to locate the .NET SDK. A preview SDK (version 10.0.100-preview.1) is available but is being blocked by your Visual Studio settings. To use preview SDKs, go to Tools -> Options -> Environment -> Preview Features and check "Use previews of the .NET SDK", or add "allowPrerelease": true to global.json.

Fixes #51524

Original prompt

This section details on the original issue you should resolve

<issue_title>SDK resolver should emit a clear message when failing to resolve due to prerelease status</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.

On an Azure DevOps machine that had VS 2022 installed and .NET 9 and 10 set up via the UseDotNet@2 task, SDK resolution failed with

The "Microsoft.DotNet.MSBuildSdkResolver" resolver attempted to resolve the SDK "Microsoft.NET.Sdk".
Warnings: null
Errors: Unable to locate the .NET SDK. Check that it is installed, your PATH is configured for the correct architecture, and that the version specified in global.json (if any) matches the installed version.

Adding a global.json with

{
  "allowPrerelease": "true"
}

worked.

Describe the solution you'd like

I'd love to see a clear error here that an SDK was found but rejected because of the allow-prerelease configuration.

Additional context

I'm not sure if this is in the hostfxr or resolver layers, but the UX is controlled here.</issue_description>

<agent_instructions>Use my suggested approach in the comments to implement the fix for allowing preview SDKs in scenarios when VS doesn't allow them. Note that most of this logic is only applicable for .NET Framework and will not run on Linux, so you won't be able to fully test as part of your own working. Think extra hard to counter this - and make sure to create new tests for the MSBuild SDK resolver for the CI pipeline to run on your behalf.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@Youssef1313 Overlaps with https://github.com//issues/51525 @baronfel We make this decision today at https://github.com/baronfel/sdk/blob/3148bcf90c1aa4c4babd96f1e601109f9115b78d/src/Resolvers/Microsoft.DotNet.SdkResolver/NETCoreSdkResolver.cs#L155-L181 - we pass in a structure that represents the VS IDE's configuration regarding prereleases. It seems like we could do the following here:
  • if SDK resolution failed
  • AND we are within VS
  • AND VS settings have disallowed previews
  • THEN retry resolution allowing previews.
  • IF that resolves successfully, log a specific error message that is more to-the-point - saying that the VS instance is configured to not allow preview SDK, but there was a preview SDK available that would have satisifed the necessary constraints.
    Thoughts?</comment_new>
    <comment_new>@rainersigwald
    That sounds good to me, I think. Slightly unfortunate to do the resolution twice, but on a failure path I don't think it's a big problem.</comment_new>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add clear error message for SDK resolver failure SDK resolver: Emit clear message when preview SDK blocked by VS settings Nov 4, 2025
Copilot finished work on behalf of baronfel November 4, 2025 22:50
Copilot AI requested a review from baronfel November 4, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK resolver should emit a clear message when failing to resolve due to prerelease status

2 participants