Skip to content

Move Windows dnx.cmd ownership from the SDK dev MSI to the sharedhost - #7719

Merged
mthalman merged 6 commits into
dotnet:mainfrom
mthalman:mthalman-ideal-funicular
Jul 21, 2026
Merged

mthalman merged 6 commits into
dotnet:mainfrom
mthalman:mthalman-ideal-funicular

Conversation

@mthalman

@mthalman mthalman commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

This is the Windows follow-up to dotnet/sdk#55116.

Today on Windows, dnx.cmd is shipped only by the SDK dev MSI; the runtime sharedhost MSI does not ship it (the Unix dnx shim already lives in the host, but Windows was never brought into line). This change moves ownership of dnx.cmd to the sharedhost package and stops the SDK component from installing it, so the two install roots stay in sync and only one MSI ever writes dnx.cmd.

This also includes a fix in dnx.cmd for a preexisting issue to ensure that dnx's exit code is propagated instead of resetting it to 0.

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
@azure-pipelines

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

@dotnet-policy-service
dotnet-policy-service Bot requested review from a team July 14, 2026 18:42
@mthalman mthalman changed the title Stop double-shipping dnx on Windows; add dnx.cmd to sharedhost Move Windows dnx.cmd ownership from the SDK dev MSI to the sharedhost Jul 14, 2026
@mthalman
mthalman requested review from akoeplinger and joeloff July 14, 2026 19:46
@mthalman
mthalman marked this pull request as ready for review July 14, 2026 19:46
Copilot AI review requested due to automatic review settings July 14, 2026 19:46
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 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 moves Windows dnx.cmd installation/ownership from the SDK “dev” MSI to the runtime sharedhost MSI so only one installer writes dnx.cmd, aligning Windows behavior with the existing Unix host-provided dnx shim. It also updates the shim to preserve the executed command’s exit code.

Changes:

  • Stop the SDK installer layout step from copying the dnx shim into the MSI/PKG install root on Windows/macOS (leaving it to sharedhost).
  • Fix dnx.cmd to propagate the dnx invocation’s exit code.
  • Add dnx.cmd to the sharedhost installer payload and install it via WiX.

Reviewed changes

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

Show a summary per file
File Description
src/sdk/src/Layout/redist/targets/GenerateInstallerLayout.targets Stops SDK MSI/PKG intermediate layout from placing dnx at the install root on Windows/macOS to avoid overlapping ownership with sharedhost.
src/sdk/src/Layout/redist/dnx.cmd Updates SDK’s dnx.cmd to propagate the exit code.
src/runtime/src/installer/pkg/sfx/installers/host.wxs Adds a sharedhost MSI component to install dnx.cmd into DOTNETHOME (and copy to PROGRAMFILES_DOTNET).
src/runtime/src/installer/pkg/sfx/installers/dotnet-host.proj Publishes dnx.cmd into the host installer staging output on non-Unix targets.
src/runtime/src/installer/pkg/sfx/installers/dnx.cmd Introduces the sharedhost-owned Windows dnx.cmd shim.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sdk/src/Layout/redist/dnx.cmd Resolved
@mthalman
mthalman requested a review from baronfel July 14, 2026 19:56
@dsplaisted

Copy link
Copy Markdown
Member

Definitely need feedback from @joeloff on the impact of this and whether it will break anything. I can imagine due to the order things run in that this could leave you without a dnx.cmd, for example.

I see a new dnx.cmd file being added, should there be a corresponding deletion of the old one?

Align the SDK zip/tarball dnx.cmd with the runtime-owned dnx.cmd: clear
SDK_VERSION before probing --list-sdks so a stale caller-environment value
cannot be used, and error out with a clear message when no SDK is found
instead of building a bogus SDK_PATH. The two copies are now identical.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@mthalman

Copy link
Copy Markdown
Member Author

I see a new dnx.cmd file being added, should there be a corresponding deletion of the old one?

No, it's still bundled by the SDK for the zip file.

@dsplaisted

Copy link
Copy Markdown
Member

No, it's still bundled by the SDK for the zip file.

Do we need to keep two copies in the source tree then? Can we use one copy as the source for both cases?

@mthalman

Copy link
Copy Markdown
Member Author

Do we need to keep two copies in the source tree then? Can we use one copy as the source for both cases?

I don't know how that would be done. Do you have suggestions?

@dsplaisted

Copy link
Copy Markdown
Member

I don't know how that would be done. Do you have suggestions?

Oh, I guess the issue is that they're in different repos. Maybe the SDK build could extract it from a runtime package, but that's a lot more complicated.

@akoeplinger

akoeplinger commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

@mthalman that's how it works for Unix though? the dnx script is extracted from the host nupkg

(I'm fine with the duplication if we want to get it in for p7 and clean up later)

Resolve conflict in GenerateInstallerLayout.targets: main added the macOS-only
dnx skip (from SDK PR #55241 codeflow); this branch extends it to Windows too.
Kept the branch version (macOS + Windows skip).

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@mthalman

Copy link
Copy Markdown
Member Author

@mthalman that's how it works for Unix though? the dnx script is extracted from the host nupkg

No, for Unix the sdk repo also has its own copy of the dnx script that is referenced when producing the SDK tarball.

@joeloff

joeloff commented Jul 16, 2026

Copy link
Copy Markdown
Member

Today, for an x64 install of multiple SDKs I have this:

image

There are three MSIs associated with DNX and it's authored as a shared component ({2E5090DD-84E9-5983-A4D7-1222CDAE23B9}) You need to ensure that moving it to the runtime has the same component GUID. That should happen automatically if you generate stable GUID.

Below is from having both x86 and x64 SDKs installed. Two separate components with unique IDs because their keypaths are different.

image

@joeloff joeloff 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.

Please fix the component authoring and verify the stable GUIDs from a build with the change against existing SDK installations.

Drop the hard-coded component GUID on the new dnx.cmd component and let WiX
generate a stable GUID from the file keypath instead. A fixed GUID shared
across per-architecture/version installers breaks MSI component reference
counting for side-by-side installs and major upgrades. Omitting the Guid
attribute matches the auto-generation pattern used by the other file/registry
components in this file.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team July 16, 2026 17:18
Pin the sharedhost dnx.cmd component to the same stable GUID the SDK dev
MSI used for [DOTNETHOME]\dnx.cmd so component identity is preserved as
ownership of the file moves from the SDK MSI to the sharedhost.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@akoeplinger

Copy link
Copy Markdown
Member

No, for Unix the sdk repo also has its own copy of the dnx script that is referenced when producing the SDK tarball.

ok, sorry, looks like I confused this with something else.

Hard-coding a single GUID makes the x86 sharedhost emit the x64 SDK's
component GUID, mismatching the x86 SDK's path-derived GUID and breaking
component ref-counting on x86. Omitting the Guid uses WiX's path-stable
generation (the same algorithm heat used for the SDK harvest), which
reproduces the correct per-architecture GUIDs automatically.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: cd879cfe-e142-4eea-9d76-c5eb4467195f
@mthalman
mthalman marked this pull request as draft July 17, 2026 13:38
@mthalman

Copy link
Copy Markdown
Member Author

Windows dnx.cmd ownership handoff — validation summary

All scenarios validated using Preview 6 SDK as the "old" version and the bits from this PR as the "new" version. The host and SDK dnx.cmd component GUIDs match per install path, so Windows Installer ref-counts the file correctly across products:

Arch Install path SDK component GUID Host cmpDnxCmd GUID Match
x64 C:\Program Files\dotnet {2E5090DD-84E9-5983-A4D7-1222CDAE23B9} {2E5090DD-84E9-5983-A4D7-1222CDAE23B9} Yes
arm64 C:\Program Files\dotnet {2E5090DD-84E9-5983-A4D7-1222CDAE23B9} {2E5090DD-84E9-5983-A4D7-1222CDAE23B9} Yes
x86 C:\Program Files (x86)\dotnet {A2FDCE00-6A7A-5F7B-A14D-0F992E92DDBB} {A2FDCE00-6A7A-5F7B-A14D-0F992E92DDBB} Yes

New install (host owns dnx.cmd)

  1. Clean machine — dnx.cmd absent.
  2. Install host — dnx.cmd present.
  3. Uninstall host — dnx.cmd removed.

Existing-SDK coexistence handoff

  1. Install old SDK — dnx.cmd present.
  2. Install new host — both co-own the file.
  3. Uninstall old SDK — dnx.cmd survives (host still owns it).
  4. Uninstall new host — dnx.cmd removed.

Host upgrade

  1. Install old host + old SDK — dnx.cmd present.
  2. Uupgrade the host — dnx.cmd survives, now co-owned by new host.
  3. Remove old SDK — dnx.cmd survives (host owns it).
  4. Install new SDK (no dnx.cmd) — file undisturbed.
  5. Uninstall host — dnx.cmd removed.

Result: PASS in all scenarios. dnx.cmd is retained as long as any product owns it and cleaned up only when the last owner is removed.

@mthalman
mthalman marked this pull request as ready for review July 20, 2026 18:53
@mthalman
mthalman requested a review from joeloff July 20, 2026 18:53
@azure-pipelines

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

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.

5 participants