setup-local-sdk
Purpose
Guide the user through installing a .NET SDK into a project-local .dotnet/
directory and wiring it up via the global.json paths feature (.NET 10+).
The examples use .NET 11, but this works with any version — prerelease or stable.
The result is a fully isolated SDK that:
- Does not modify the system-wide .NET installation.
- Is picked up automatically by
dotnetcommands from the project root. - Can be deleted to revert (
rm -rf .dotnet/orRemove-Item -Recurse -Force .\.dotnet).
When NOT to use
- User wants a system-wide install — direct to the official installer.
- Host
dotnetis older than v10 —pathsdoesn't exist; explain and stop. - User needs a runtime-only install —
pathsapplies to SDK resolution only.
Inputs / Prerequisites
Prerequisites
- A .NET 10+ SDK is installed globally — run
dotnet --version; major ≥ 10. - curl (macOS/Linux) or PowerShell (Windows) is available.
Workflow
Step 1 — Clarify what to install
If the user didn't specify, ask what .NET SDK version they want (e.g., "latest
.NET 11 preview" or an exact version like 11.0.100-preview.2.26159.112).
Map the answer to --channel/--quality or --version flags.
Step 2 — Verify .NET 10+ host
If the user already provided dotnet --version output, treat that as the
authoritative version for their machine. Do not override it with the agent
workspace's version; if the two differ, explain that the workspace differs and
continue advising for the user's machine.
If major version < 10, stop before downloading anything: the paths feature
requires a .NET 10+ host SDK. Tell the user to install .NET 10 or later
system-wide first, then return to the local SDK setup.
Step 3 — Detect operating system
Run uname -s 2>/dev/null. If it succeeds (including MINGW*, MSYS*, CYGWIN* —
these are bash-capable environments like Git Bash) → use bash/dotnet-install.sh.
If it fails (native Windows without Git Bash) → use PowerShell/dotnet-install.ps1.
Step 4 — Check for existing local SDK
macOS / Linux:
Windows (PowerShell):
If .dotnet/ exists, ask: update with the new version, or skip and keep it?
Step 5 — Download and run the install script
macOS / Linux:
Windows (PowerShell):
For exact versions: use --version <VERSION> (bash) or -Version <VERSION> (PowerShell)
instead of channel/quality flags. The install scripts are from Microsoft's official
URLs: https://dot.net/v1/dotnet-install.sh and https://dot.net/v1/dotnet-install.ps1.
Step 6 — Identify the installed version
Record the exact version string (e.g., 11.0.100-preview.2.26159.112) for global.json.
Step 7 — Create or update global.json
paths:.dotnetfirst (local priority),$host$= system-wide fallback.rollForward: "latestFeature": use for latest-preview or floating feature-band installs.- Exact version requests: use
rollForward: "disable"so SDK resolution doesn't move to a different feature band. allowPrerelease: set totrueonly when installing a prerelease SDK. Omit for stable versions.errorMessage: include only when team install scripts are created (Step 10). Otherwise omit.
If global.json already exists, merge carefully: preserve existing properties (msbuild-sdks,
tools, etc.) and only add/update the sdk section. Read the existing file first, update/add
the sdk object, then write it back. This ensures cross-project config (e.g., MSBuild settings)
isn't lost. Always back up the original file (e.g., global.json.bak) before modifying.
Minimal config (when version pinning isn't needed):
{"sdk":{"paths":[".dotnet","$host$"]}}
Step 8 — Update .gitignore
macOS / Linux (or Git Bash):
Windows (PowerShell):
Step 9 — Install workloads (if requested)
Only do this after global.json and .gitignore are complete, so a slow or
platform-limited workload install does not prevent the base local SDK setup from
being usable.
If the user mentioned MAUI, mobile, workload, Blazor WASM, or cross-platform, install using the local binary (no sudo needed):
Verify: ./.dotnet/dotnet workload list (or .\.dotnet\dotnet.exe workload list).
For MAUI, pick a workload supported by the current OS and target platform. On
Linux, the full maui meta-workload is not available; use a supported workload
such as maui-android when Android is the target, or explain the platform
limitation and ask which target to configure.
Always use the local dotnet binary for workload commands. Workload metadata is stored relative to the host process's dotnet root. The system
dotnetputs metadata in the wrong location. (See dotnet/sdk#49825.)
Step 10 — Create team install scripts
Create if user mentioned "team", "share", "CI", "scripts", etc. Otherwise offer.
These examples back up global.json and preserve existing settings. The bash script
uses jq when an existing global.json must be patched; if jq is unavailable,
it refuses to overwrite the file and prints the settings to merge manually.
Adapt script variables to the install choice from Step 1: exact versions should
use --version / -Version and rollForward: "disable"; channel installs should
use channel/quality and only set allowPrerelease: true for prerelease SDKs.
If global.json already pins sdk.version and the user mainly needs team
scripts, reuse that version in the scripts and update global.json first; do
not start a long SDK download just to discover the version. When the user asks
for both setup and scripts, create the scripts/config before any long install so
the reproducible setup exists even if download or workload installation is slow.
install-dotnet.sh:
install-dotnet.ps1:
Commit these scripts to the repo so teammates can run them.
Step 11 — Verify SDK resolution
Output should match the locally installed version. If not, check: global.json
location, paths array contents, host dotnet version ≥ 10.
Step 12 — Summarize and explain cleanup
Tell the user: SDK installed, global.json configured, .dotnet/ gitignored, system
install untouched. Cleanup: delete .dotnet/, remove paths/errorMessage from
global.json, optionally delete install scripts. Include the final global.json
sdk values (or a short snippet) so the user can see the configured version,
paths, and any errorMessage. If workloads were requested, include the local
dotnet workload install ... command used and the workload verification result
or the exact blocker if the workload could not be installed.


