Skip to content

Add Windows dnx.cmd shim to dotnet-host (sharedhost) package - #130686

Closed
mthalman wants to merge 2 commits into
dotnet:mainfrom
mthalman:mthalman-dnx-cmd-windows-shim
Closed

mthalman wants to merge 2 commits into
dotnet:mainfrom
mthalman:mthalman-dnx-cmd-windows-shim

Conversation

@mthalman

@mthalman mthalman commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

Why

Today on Windows, the dnx launcher is shipped only by the SDK dev MSI; the sharedhost MSI does not ship it. That leaves dnx owned by a different installer than dotnet.exe, so the two can target different roots and drift out of sync (see dotnet/sdk#55116).

This moves ownership of the Windows dnx launcher to the sharedhost MSI, so dnx ships and uninstalls alongside dotnet.exe in every root the host is installed to. It is the Windows follow-up to the Unix dnx shim added in #129258.

What

  • Adds src/installer/pkg/sfx/installers/dnx.cmd, a Windows batch mirror of the existing Unix dnx shim: it resolves dotnet.exe next to itself, picks the newest installed SDK from dotnet --list-sdks, and dispatches dotnet exec sdk\<version>\dotnet.dll dnx %*. It ends with endlocal & exit /b %ERRORLEVEL% so it propagates dnx's exit code.
  • dotnet-host.proj: publishes dnx.cmd on Windows only (TargetsUnix != 'true'), as a sibling to the existing Unix dnx entry. No chmod is applied (that remains Unix-only).
  • host.wxs: adds a new cmpDnxCmd component that installs dnx.cmd into DOTNETHOME and CopyFiles it to PROGRAMFILES_DOTNET, mirroring how cmpCoreHost handles dotnet.exe so dnx lands in both roots.

Notes for reviewers

  • This must ship in the same release as the paired dotnet/sdk change (Stop shipping dnx from the SDK component on Windows sdk#55268), which stops the SDK dev MSI from shipping dnx.cmd on Windows. The two changes must land together: adding it here without the SDK removal would give dnx.cmd two owners (a silent cross-MSI overlap, since Windows MSI does not hard-fail on it), while merging the SDK removal without this change would leave Windows with no dnx at all.
  • Unlike the SDK's original dnx.cmd, this version adds a missing-SDK guard (if not defined SDK_VERSION ... exit /b 1). That matches the Unix shim's behavior and is the correct choice for the host package, which can be installed without any SDK present.
  • The component GUID is fixed for install/upgrade stability.

Note

This pull request was authored with the assistance of GitHub Copilot.

Mirror the Unix dnx shim on Windows by shipping dnx.cmd from the
sharedhost (dotnet-host) MSI so both install roots stay in sync.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b17adf1a-bcda-445b-b5e7-0b5fe876851f
Copilot AI review requested due to automatic review settings July 14, 2026 13:34
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

This PR adds a Windows dnx.cmd shim to the dotnet-host (sharedhost) installer/package output so dnx is installed/uninstalled alongside dotnet.exe in the shared host roots.

Changes:

  • Add a new Windows batch shim (dnx.cmd) that dispatches to dotnet exec ... dnx.
  • Publish dnx.cmd on non-Unix targets from dotnet-host.proj (mirroring the existing Unix dnx publish).
  • Install dnx.cmd via the sharedhost MSI and copy it into PROGRAMFILES_DOTNET similarly to dotnet.exe.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/installer/pkg/sfx/installers/host.wxs Adds an MSI component to install/copy dnx.cmd into both DOTNETHOME and Program Files roots.
src/installer/pkg/sfx/installers/dotnet-host.proj Publishes dnx.cmd on Windows (non-Unix) builds alongside the existing Unix dnx publish behavior.
src/installer/pkg/sfx/installers/dnx.cmd Introduces the Windows dnx shim batch script.

Comment on lines +21 to +23
"%DOTNET%" exec "%SDK_PATH%" dnx %*

endlocal
A trailing bare `endlocal` resets ERRORLEVEL to 0, so callers saw
success even when `dotnet exec ... dnx` failed. Use
`endlocal & exit /b %ERRORLEVEL%` so the child process exit code is
returned to the caller.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b17adf1a-bcda-445b-b5e7-0b5fe876851f
Copilot AI review requested due to automatic review settings July 14, 2026 13:46

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines +7 to +21
set "DOTNET=%~dp0dotnet.exe"

set "SDK_VERSION="
for /f "tokens=1" %%i in ('"%DOTNET%" --list-sdks') do (
set "SDK_VERSION=%%i"
)

if not defined SDK_VERSION (
echo Error: dnx requires a .NET SDK to be installed, but none was found. 1>&2
exit /b 1
)

set "SDK_PATH=%~dp0sdk\%SDK_VERSION%\dotnet.dll"

"%DOTNET%" exec "%SDK_PATH%" dnx %*
mthalman added a commit to mthalman/sdk that referenced this pull request Jul 14, 2026
The Windows zip-layout dnx.cmd ended with a bare endlocal, which resets
ERRORLEVEL to 0 and swallowed the exit code from 'dotnet exec ... dnx'.
Callers would see success even when dnx failed. Mirror the sharedhost
dnx.cmd fix (dotnet/runtime#130686) by exiting with the propagated code.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@mthalman mthalman closed this Jul 14, 2026
mthalman added a commit to dotnet/dotnet that referenced this pull request Jul 21, 2026
Windows follow-up to the dnx double-ship fix (dotnet/sdk#55241 for macOS).
On Windows the SDK 'dev' MSI and the runtime sharedhost MSI both wrote
dnx.cmd to the same install root, creating overlapping component packages
(silent last-writer-wins / ref-count uninstall risk). Move dnx.cmd ownership
to the sharedhost package and stop the SDK component from installing it.

SDK (src/sdk):
- GenerateInstallerLayout.targets: skip the dnx copy into the dev-MSI
  intermediate layout on Windows too (already skipped on macOS). LayoutDnxShim
  still emits dnx.cmd into the base redist layout (zip/tarball).
- redist/dnx.cmd: end with 'endlocal & exit /b %ERRORLEVEL%' so the shim
  propagates dnx's exit code instead of swallowing it.

Runtime (src/runtime):
- New installers/dnx.cmd: Windows shim mirroring the Unix dnx shim, with a
  missing-SDK guard and exit-code propagation.
- dotnet-host.proj: publish dnx.cmd to the sharedhost output on Windows.
- host.wxs: add cmpDnxCmd component installing dnx.cmd to DOTNETHOME with a
  CopyFile to PROGRAMFILES_DOTNET, mirroring cmpCoreHost.

Mirrors dotnet/sdk#55268 and dotnet/runtime#130686.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants