Skip to content

Install the SDK from sdk.version when tools.dotnet is not specified - #17816

Merged
ViktorHofer merged 5 commits into
dotnet:mainfrom
ViktorHofer:download-sdk-version-switch
Nov 18, 2026
Merged

ViktorHofer merged 5 commits into
dotnet:mainfrom
ViktorHofer:download-sdk-version-switch

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

When global.json doesn't specify tools.dotnet, Arcade now installs/uses the SDK version specified in sdk.version. No opt-in switch is needed.

{
  "sdk": {
    "version": "10.0.100",
    "rollForward": "latestFeature"
  }
}

This lets repositories specify the SDK version only once, under sdk.version, and leverage tools like Dependabot to keep it up-to-date. Dependabot doesn't know about tools.dotnet as it's an Arcade-only concept.

Behavior

  • tools.dotnet specified: unchanged, tools.dotnet is installed (it wins over sdk.version).
  • No tools.dotnet, sdk.version specified: sdk.version is installed. Previously this was a hard error in bash and, on Windows, either an error (dotnet engine) or no SDK bootstrapping (tools.vs repos).
  • Neither specified: error (bash and dotnet engine), same as before. Windows tools.vs-only repos keep using VS MSBuild without bootstrapping an SDK.
  • On Windows, a tools.vs + sdk.version repo is now treated like today's tools.vs + tools.dotnet repos (e.g. roslyn, msbuild, wpf): VS MSBuild is used and the SDK is bootstrapped into .dotnet and prepended to PATH. None of the ~40 public Arcade repos I checked use tools.vs without tools.dotnet.
  • The tools section in global.json is now optional on Windows too (previously tools.ps1 threw when it was missing).

Changes

  • eng/common/tools.ps1: GetDotNetSdkVersion returns tools.dotnet, else sdk.version, else $null. GlobalJsonSpecifiesDotNetSdk (used by InitializeBuildTool and GetDefaultMSBuildEngine) is true when either is set. A missing tools section is defaulted to an empty object. The runtimes check uses Get-Member, so it no longer throws under strict mode for an empty tools object.
  • eng/common/tools.sh: InitializeDotNetCli reads the version via ReadDotNetSdkVersion (jq '.tools.dotnet // .sdk.version', plus a regex fallback without jq; the sdk.version regex skips over quoted strings so braces inside e.g. sdk.errorMessage don't break it).
  • LocateDotNet (Arcade SDK task) reads the version through an internal TryGetDotNetSdkVersion method (System.Text.Json) with the same precedence, instead of a "dotnet" regex.
  • Removed the unused CheckRequiredDotNetVersion task (and its UsingTask). It had no usages and would otherwise also have needed updating.
  • Documentation/ArcadeSdk.md: documented the fallback.

Other scripts (dotnet.*, darc-init.*, vmr-sync.*, post-build/*) go through InitializeDotNetCli and pick this up automatically.

Note: Maestro/darc only bumps the SDK (tools.dotnet and sdk.version) in repos that specify tools.dotnet. Repos that drop it rely on e.g. Dependabot for SDK updates. Arcade and the VMR must keep tools.dotnet since darc reads it from the source repo.

Validation

  • .\eng\common\build.ps1 -restore -build -projects src\Microsoft.DotNet.Arcade.Sdk.Tests\Microsoft.DotNet.Arcade.Sdk.Tests.csproj: passed (0 warnings, 0 errors).
  • dotnet test artifacts\bin\Microsoft.DotNet.Arcade.Sdk.Tests\Debug\net12.0\Microsoft.DotNet.Arcade.Sdk.Tests.dll --filter "FullyQualifiedName~LocateDotNetTests|FullyQualifiedName~InstallDotNetCoreTests": passed (9/9, including 6 LocateDotNetTests cases).
  • Ran the scripts against synthetic repos with eight global.json shapes: tools.dotnet only; both; sdk.version only without a tools section; sdk.version + tools.vs; tools.vs only; neither; sdk.errorMessage containing {, } and escaped quotes before version; sdk.version + tools.runtimes. Each case checks version, default engine and runtimes detection:
    • PowerShell 7 and Windows PowerShell 5.1, each with and without an extra Set-StrictMode -Version 2.0 (tools.ps1 enables it itself): passed (32/32).
    • bash 5.2 (WSL, set -eu), with and without jq: passed (16/16).
  • End-to-end: InitializeBuildTool with only sdk.version and no tools section resolved an installed SDK via DOTNET_INSTALL_DIR (pwsh and Windows PowerShell): passed.

To double check:

Allow repositories to set "tools": { "downloadSdkVersion": true } in global.json
so that eng/common/tools.ps1 and tools.sh install the SDK version specified in
"sdk.version" instead of "tools.dotnet". This lets repos specify the SDK version
once and use tools like Dependabot (which only understand "sdk.version") to keep
it up-to-date.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 92e5d4ad-1f02-4608-88b1-2420560b5813
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

SDK bootstrapping can fail on braces in quoted error messages, and LocateDotNet and CheckRequiredDotNetVersion still require the legacy dotnet key instead of honoring the documented sdk.version configuration.

2 open issues
What changed in this PR

Adds an opt-in tools.downloadSdkVersion setting so Arcade’s bootstrap scripts can install the SDK from sdk.version, avoiding duplicate version declarations and supporting Dependabot updates.

Changes:

  • Adds SDK-version selection and missing-version validation to Bash and PowerShell.
  • Updates PowerShell build-tool detection to recognize the new switch.
  • Documents the switch, its precedence, and an example configuration.
File Description
eng/​common/​tools.sh Adds SDK-version selection through jq or a regex fallback.
eng/​common/​tools.ps1 Adds version-selection helpers and updates build-tool detection.
Documentation/​ArcadeSdk.md Documents the opt-in setting and configuration example.

Review effort: Balanced

Comment thread Documentation/ArcadeSdk.md Resolved
Comment thread eng/common/tools.sh Resolved
…sh fallback

- LocateDotNet and CheckRequiredDotNetVersion now read the SDK version through a
  shared GlobalJson helper that honors tools.downloadSdkVersion (sdk.version)
  and otherwise reads tools.dotnet.
- tools.sh: the no-jq fallback regex consumes quoted strings as a whole so braces
  inside e.g. sdk.errorMessage don't break parsing.
- tools.ps1: only a JSON boolean true enables the switch, consistent with
  tools.sh and the tasks.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 92e5d4ad-1f02-4608-88b1-2420560b5813
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The no-jq fallback can match comments or properties outside the root tools object, overriding an explicit false value and causing bootstrapping to select the wrong SDK version or fail.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Restrict the fallback check to tools.downloadSdkVersion

eng/​common/​tools.sh:142

Without jq, this regex enables the switch from comments or properties outside tools, even when tools.downloadSdkVersion is explicitly false. For example, // "downloadSdkVersion": true or "custom": { "downloadSdkVersion": true } makes bootstrapping use sdk.version instead of tools.dotnet, or fail if sdk.version is absent. Make the fallback ignore comments and check only the boolean property in the root tools object.

1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 92e5d4ad-1f02-4608-88b1-2420560b5813
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:20
@ViktorHofer

Copy link
Copy Markdown
Member Author

Re the no-jq fallback matching downloadSdkVersion outside of tools / in comments: comments aren't supported in global.json by the Arcade scripts (the jq and Windows PowerShell paths already fail on them), and matching the key elsewhere in the file is an accepted limitation of the simple regex fallback. Not changing this.

Also removed the unused CheckRequiredDotNetVersion task in 3b77c26, so only LocateDotNet needed updating for the switch.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Removing the public CheckRequiredDotNetVersion task and its registration risks breaking downstream consumers without following the documented breaking-change process.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:25
The helper only has a single consumer now that CheckRequiredDotNetVersion is gone.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 92e5d4ad-1f02-4608-88b1-2420560b5813

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Removing a public MSBuild task can break consuming repositories, requiring human assessment of downstream compatibility and compliance with the breaking-change policy.

No open issues 🎉

Review effort: Balanced

Drop the tools.downloadSdkVersion opt-in switch. Arcade now installs
'tools.dotnet' if specified, otherwise 'sdk.version'. In tools.ps1, the
'tools' section in global.json is now optional and the runtimes check
no longer throws under strict mode for an empty 'tools' object.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e0dbec8f-3832-4bb7-a663-ed18780aec88
Copilot AI balanced review requested due to automatic review settings November 18, 2026 16:10
@ViktorHofer ViktorHofer changed the title Add tools.downloadSdkVersion switch to install the SDK from sdk.version Install the SDK from sdk.version when tools.dotnet is not specified Nov 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to evaluate downstream compatibility risks from removing a public build task and SDK reuse when no version is configured.

No open issues 🎉

Review effort: Balanced

@ViktorHofer
ViktorHofer enabled auto-merge (squash) November 18, 2026 17:14
@ViktorHofer
ViktorHofer merged commit 9f5b80b into dotnet:main Nov 18, 2026
10 of 12 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
@ViktorHofer

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@ViktorHofer backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 9f5b80b49da9b9d6b044e3b107ad678f1c8d0e77

Auto-merging Documentation/ArcadeSdk.md
Auto-merging eng/common/tools.ps1
Auto-merging eng/common/tools.sh
CONFLICT (modify/delete): src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs deleted in 9f5b80b49 (Install the SDK from sdk.version when tools.dotnet is not specified (#17816)) and modified in HEAD.  Version HEAD of src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs left in tree.
Auto-merging src/Microsoft.DotNet.Arcade.Sdk/src/LocateDotNet.cs
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Arcade.Sdk/src/LocateDotNet.cs
Auto-merging src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props
error: could not apply 9f5b80b49... Install the SDK from sdk.version when tools.dotnet is not specified (#17816)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add tools.downloadSdkVersion switch to install the SDK from sdk.version
Applying: Address PR feedback: honor downloadSdkVersion in SDK tasks, harden bash fallback
Using index info to reconstruct a base tree...
M	eng/common/tools.ps1
M	eng/common/tools.sh
M	src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs
M	src/Microsoft.DotNet.Arcade.Sdk/src/LocateDotNet.cs
Falling back to patching base and 3-way merge...
Auto-merging eng/common/tools.ps1
Auto-merging eng/common/tools.sh
Auto-merging src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs
Auto-merging src/Microsoft.DotNet.Arcade.Sdk/src/LocateDotNet.cs
Applying: Remove unused CheckRequiredDotNetVersion task
Using index info to reconstruct a base tree...
M	src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs
M	src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs deleted in Remove unused CheckRequiredDotNetVersion task and modified in HEAD.  Version HEAD of src/Microsoft.DotNet.Arcade.Sdk/src/CheckRequiredDotNetVersion.cs left in tree.
Auto-merging src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0003 Remove unused CheckRequiredDotNetVersion task
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

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.

3 participants