Skip to content

Update the dnx script to use the newest SDK - #54472

Merged
JoeRobich merged 5 commits into
mainfrom
dev/jorobich/update-dnx
Jun 4, 2026
Merged

Update the dnx script to use the newest SDK#54472
JoeRobich merged 5 commits into
mainfrom
dev/jorobich/update-dnx

Conversation

@JoeRobich

Copy link
Copy Markdown
Member

The dnx scripts worked by invoking dotnet dnx. This creates issues in folders where a global.json has pinned a version of the SDK which does not support the dnx command.

We change the behavior of the scripts to use dotnet--list-sdks to get the list of installed SDKs. We then take the last entry, which should be the latest as the list is sorted. We then directly execute that version of the dotnet.dll. This allows the dnx script to script to work despite any global.json.

Resolves #51085

The dnx scripts worked by invoking `dotnet dnx`. This creates issues in folders where a global.json has pinned a version of the SDK which does not support the `dnx` command.

We change the behavior of the scripts to use `dotnet--list-sdks` to get the list of installed SDKs. We then take the last entry, which should be the latest as the list is sorted. We then directly execute that version of the dotnet.dll. This allows the dnx script to script to work despite any global.json.

Resolves #51085
Copilot AI review requested due to automatic review settings May 27, 2026 20:23
@JoeRobich
JoeRobich requested a review from dsplaisted May 27, 2026 20:23

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.

Pull request overview

Updates the dnx launch scripts so they bypass global.json SDK selection by locating the newest installed SDK and directly executing its dotnet.dll, addressing scenarios where dotnet dnx would be routed to an older SDK that lacks the required command.

Changes:

  • Windows (dnx.cmd): resolve latest SDK version via dotnet --list-sdks, then dotnet exec <sdk>\dotnet.dll tool exec ....
  • Unix (dnx): resolve latest SDK version via dotnet --list-sdks pipeline, then dotnet exec <sdk>/dotnet.dll tool exec ....
Show a summary per file
File Description
src/Layout/redist/dnx.cmd Switches from dotnet dnx to selecting a latest SDK and executing its dotnet.dll to avoid global.json pinning.
src/Layout/redist/dnx Same behavior change as Windows script for Unix environments.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread src/Layout/redist/dnx.cmd
Comment thread src/Layout/redist/dnx Outdated
Comment thread src/Layout/redist/dnx.cmd
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Joey Robichaud <joseph.robichaud@microsoft.com>
@agocke

agocke commented May 27, 2026

Copy link
Copy Markdown
Member

Have you considered just making dnx into an apphost that has a relative pointer to a dnx dll that sits next to dotnet.dll to call into it directly? Then you would just be using standard apphost resolution.

@dsplaisted

Copy link
Copy Markdown
Member

Have you considered just making dnx into an apphost that has a relative pointer to a dnx dll that sits next to dotnet.dll to call into it directly? Then you would just be using standard apphost resolution.

We've thought of using a NativeAOT app for the dnx shim.

We want to avoid having files in the root that are tied to a specific SDK version, as it's hard to make sure it's the right version when installing or upgrading multiple SDKs. It sounds like an apphost with a relative pointer would be tied to a specific SDK version.

What I'd prefer is a parameter we could pass to the dotnet executable that would tell it to ignore global.json, rather than these scripts having to find the latest SDK and invoke dotnet.dll directly. I think invoking dotnet.dll directly won't necessarily be the right thing as we're moving some functionality to AOT.

@JoeRobich

Copy link
Copy Markdown
Member Author

What I'd prefer is a parameter we could pass to the dotnet executable that would tell it to ignore global.json, rather than these scripts having to find the latest SDK and invoke dotnet.dll directly.

@dsplaisted That was my initial plan. But it seems we do not want to make changes to the muxer or the corehost at this time.

I think invoking dotnet.dll directly won't necessarily be the right thing as we're moving some functionality to AOT.

Could we handle this by first looking for an executable in the SDK folder then falling back to dotnet.dll?

Comment thread src/Layout/redist/dnx Outdated
SDK_VERSION=$(DOTNET_MULTILEVEL_LOOKUP=0 "$DOTNET" --list-sdks | tail -1 | cut -d' ' -f1)
SDK_PATH="$(dirname "$0")/sdk/$SDK_VERSION/dotnet.dll"

DOTNET_MULTILEVEL_LOOKUP=0 "$DOTNET" exec "$SDK_PATH" tool exec "$@" No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should not set MLL and should call dnx instead of tool exec

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated!

@marcpopMSFT

Copy link
Copy Markdown
Member

If there are no other options that work for 10 (which so far, we haven't come up with one), I think we're ok with this as a stopgap. The main concerns are that we didn't want to churn the dnx script as it's meant to be a singleton so any churn creates issues of "which one does the customer have" AND calling dotnet.dll doesn't work long-term as we hope eventually to move dnx into dotnet-aot.dll.

@dsplaisted dsplaisted left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not really qualified to review sh or powershell scripts, but I am OK with this approach overall.

Comment thread src/Layout/redist/dnx.cmd Outdated
@JoeRobich

Copy link
Copy Markdown
Member Author

@marcpopMSFT Am I good to start a backport of this to 10.0.4xx?

@JoeRobich

Copy link
Copy Markdown
Member Author

/backport to release/10.0.3xx

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.3xx (link to workflow run)

@JoeRobich JoeRobich added the breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug label Jun 4, 2026
@dotnet-policy-service

dotnet-policy-service Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET SDK Breaking Change Notification email list.

You can refer to the .NET SDK breaking change guidelines

@JoeRobich
JoeRobich merged commit 22c3477 into main Jun 4, 2026
25 of 28 checks passed
@JoeRobich
JoeRobich deleted the dev/jorobich/update-dnx branch June 4, 2026 18:58
nagilson added a commit to nagilson/sdk that referenced this pull request Jun 4, 2026
The earlier merge+revert on this branch left the dnx launch scripts at their pre-dotnet#54472 form, which would have reverted main's dnx simplification. Restore them to match upstream/main so this PR only changes dotnetup acquisition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dnx forwards arguments to configured .NET SDK which may or may not be .NET 10+

6 participants