Skip to content

Make target OS/arch in Bundler and TargetInfo non-optional#126437

Merged
elinor-fung merged 10 commits intomainfrom
copilot/remove-optional-os-arch-args
Apr 7, 2026
Merged

Make target OS/arch in Bundler and TargetInfo non-optional#126437
elinor-fung merged 10 commits intomainfrom
copilot/remove-optional-os-arch-args

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

This pull request refactors how the target operating system and architecture are handled in the bundling logic, making both parameters required rather than optional. It removes fallback logic that previously inferred these values from the current runtime environment, leading to more explicit and predictable behavior. The changes also update tests and utilities to accommodate this new requirement.

Bundler and TargetInfo API changes:

  • The Bundler and TargetInfo constructors now require explicit OSPlatform and Architecture arguments, removing support for optional values and fallback to the host environment. [1] [2]
  • The static fallback logic (HostOS) in TargetInfo is removed, so the OS must always be specified.

Test and utility updates:

  • Test code in BundlerConsistencyTests and SingleFileTestApp is updated to pass the required OSPlatform and Architecture values, using a new Binaries.CurrentOSPlatform helper and RuntimeInformation.OSArchitecture. [1] [2] [3]
  • A new static property, CurrentOSPlatform, is added to the Binaries utility class to encapsulate platform detection logic for tests.

Resolves #101548

cc @dotnet/appmodel @AaronRobinsonMSFT

Copilot AI and others added 2 commits April 2, 2026 00:06
…ed OS/arch detection

Add a new optional `runtimeIdentifier` parameter to both the `TargetInfo` and
`Bundler` constructors. When provided, the runtime identifier string (e.g.,
"linux-x64", "win-arm64") is parsed to determine the target OS and architecture,
eliminating the need for callers to implement their own RID parsing logic.

Explicit `os` and `arch` parameters take precedence over RID-derived values.
When neither the RID nor explicit parameters are provided, existing behavior
(defaulting to the current OS/arch) is preserved.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/080a2b19-6edb-49cd-aa57-3169ae7c998c

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
…iscV64 extension

The NETFRAMEWORK Architecture extension already provides LoongArch64, so
the #if !NETFRAMEWORK guard was incorrectly excluding it from RID parsing
on .NET Framework. Add RiscV64 extension for NETFRAMEWORK parity and
remove the conditional compilation from ParseRuntimeIdentifier.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/080a2b19-6edb-49cd-aa57-3169ae7c998c

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove optional OS/arch arguments in Bundler and TargetInfo Add runtimeIdentifier parameter to Bundler and TargetInfo for RID-based OS/arch detection Apr 2, 2026
Copilot AI requested a review from elinor-fung April 2, 2026 00:13
Copilot AI and others added 2 commits April 2, 2026 00:35
Make the OS and architecture parameters required (non-nullable) in both
the TargetInfo and Bundler constructors, removing the previous approach
of adding a runtimeIdentifier parameter.

- TargetInfo: os and arch are now required positional parameters
- Bundler: targetOS and targetArch are now required positional parameters
  (3rd and 4th, after hostName and outputDir)
- Remove ParseRuntimeIdentifier method and HostOS fallback detection
- Update all test callers to pass explicit OS/arch values
- Keep #nullable enable, RiscV64/LoongArch64 extensions, Version? nullability

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/181f3158-29d6-449a-b597-e998407a7c29

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
… non-optional

Restore the original parameter order (options, targetOS, targetArch) and
make all three required. This avoids changing the parameter order which
would be more disruptive to callers.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/181f3158-29d6-449a-b597-e998407a7c29

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
…ameworkVersion non-optional

- Add Binaries.CurrentOSPlatform matching the original _hostOS logic
  (Linux → OSX → FreeBSD → Windows fallback)
- Use shared property in both BundlerConsistencyTests and SingleFileTestApp
- Make targetFrameworkVersion non-optional on both TargetInfo and Bundler
- All callers now pass explicit version (Environment.Version as default)

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/fb0ea73a-20ee-458f-ad6f-9362fdbdb6c7

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
…getInfo

Restore the ?? Environment.Version fallback for FrameworkVersion and
remove the #nullable enable directive that was added.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/111adf2b-fa15-47e9-9942-56791bd4bfe9

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@elinor-fung elinor-fung changed the title Add runtimeIdentifier parameter to Bundler and TargetInfo for RID-based OS/arch detection Make target OS/arch in Bundler and TargetInfo non-optional Apr 3, 2026
@elinor-fung elinor-fung marked this pull request as ready for review April 3, 2026 18:57
Copilot AI review requested due to automatic review settings April 3, 2026 18:57
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @elinor-fung
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors HostModel bundling APIs to require explicit target OS and architecture, removing implicit host-detection defaults and updating installer tests/utilities accordingly. Also introduces RiscV64 handling for Architecture when building under .NET Framework.

Changes:

  • Make Bundler and TargetInfo require non-optional OSPlatform and Architecture inputs.
  • Update installer test helpers and test cases to pass explicit OS/arch (via Binaries.CurrentOSPlatform and RuntimeInformation.OSArchitecture).
  • Add Architecture.RiscV64 shim for NETFRAMEWORK builds.

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/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs Updates constructor signature to require explicit target OS/arch and framework version.
src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs Removes nullable OS/arch inputs and internal host OS inference; adds RiscV64 for NETFRAMEWORK.
src/installer/tests/TestUtils/Binaries.cs Adds CurrentOSPlatform helper for tests to pass explicit target OS into bundling APIs.
src/installer/tests/TestUtils/SingleFileTestApp.cs Updates bundling helper to pass explicit OS/arch/version into Bundler.
src/installer/tests/Microsoft.NET.HostModel.Tests/Bundle/BundlerConsistencyTests.cs Updates bundler construction in tests to provide explicit OS/arch/version.

…getInfo.HostOS logic

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f527b3fb-f65c-493a-bea9-97971e127876

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/a3713efd-dc6a-415b-bdde-9d5c860f6ba2

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
…e dead Illumos extension

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f8b8e2af-d4e9-44c9-a9c7-e5c4128933ed

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

@elinor-fung I assume this requires some update to the SDK or were we never relying on the default behavior?

@elinor-fung
Copy link
Copy Markdown
Member

We were never relying on the default behaviour. Usage in the SDK always passes these parameters: https://github.com/dotnet/sdk/blob/96683a0ad81c5694820f7824342a4ca5079bdd64/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs#L81-L89

I had that in the PR description previously, but forgot to add it back after CCA wrote over it...

@elinor-fung
Copy link
Copy Markdown
Member

/ba-g the legs build analysis indicates it is waiting on all show as completed and green

@elinor-fung elinor-fung merged commit bfb2e88 into main Apr 7, 2026
87 checks passed
@elinor-fung elinor-fung deleted the copilot/remove-optional-os-arch-args branch April 7, 2026 17:07
@github-project-automation github-project-automation bot moved this to Done in AppModel Apr 7, 2026
#if NETFRAMEWORK
public static OSPlatform FreeBSD => OSPlatform.Create("FREEBSD");
#endif
public static OSPlatform Illumos => OSPlatform.Create("ILLUMOS");
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.

Both freebsd and illumos were used once. Usage of both were removed but kept definition of one?

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.

@copilot Create a new PR to remove FreeBSD and the OSPlatform extension here.

jkotas pushed a commit that referenced this pull request Apr 8, 2026
Per
#126437 (comment),
the `FreeBSD` `OSPlatform` extension in `PlatformExtensions` was defined
but never used after PR #126437 removed its only usage. This PR removes
the unused `extension(OSPlatform)` block while keeping the still-used
`extension(Architecture)` block for `LoongArch64`.

cc @elinor-fung @am11

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Apr 9, 2026
…6437)

This pull request refactors how the target operating system and
architecture are handled in the bundling logic, making both parameters
required rather than optional. It removes fallback logic that previously
inferred these values from the current runtime environment, leading to
more explicit and predictable behavior.

**Bundler and TargetInfo API changes:**

* The `Bundler` and `TargetInfo` constructors now require explicit
`OSPlatform` and `Architecture` arguments, removing support for optional
values and fallback to the host environment.
* The static fallback logic (`HostOS`) in `TargetInfo` is removed, so
the OS must always be specified.
* Usage in the SDK always passes these parameters

**Test and utility updates:**

* Test code in `BundlerConsistencyTests` and `SingleFileTestApp` is
updated to pass the required `OSPlatform` and `Architecture` values,
using a new `Binaries.CurrentOSPlatform` helper and
`RuntimeInformation.OSArchitecture`.
* A new static property, `CurrentOSPlatform`, is added to the `Binaries`
utility class to encapsulate platform detection logic for tests.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Apr 9, 2026
…#126612)

Per
dotnet#126437 (comment),
the `FreeBSD` `OSPlatform` extension in `PlatformExtensions` was defined
but never used after PR dotnet#126437 removed its only usage. This PR removes
the unused `extension(OSPlatform)` block while keeping the still-used
`extension(Architecture)` block for `LoongArch64`.

cc @elinor-fung @am11

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

OS/arch optional arguments in Bundler and TargetInfo

5 participants