Skip to content

Add platform-specific build infrastructure (TargetOS, TARGET_WINDOWS…)#13523

Draft
JeremyKuhne wants to merge 1 commit intodotnet:mainfrom
JeremyKuhne:targetos
Draft

Add platform-specific build infrastructure (TargetOS, TARGET_WINDOWS…)#13523
JeremyKuhne wants to merge 1 commit intodotnet:mainfrom
JeremyKuhne:targetos

Conversation

@JeremyKuhne
Copy link
Copy Markdown
Member

@JeremyKuhne JeremyKuhne commented Apr 10, 2026

This will facilitate conditionalizing OS specific code to reduce assembly size and make VMR integration easier. In particular, shifting to direct interop on Windows with CsWin32 will improve startup time and allow more code to run in AOT scenarios (notably in parts of the CLI).

Introduce centralized OS/architecture detection and platform-specific
C# preprocessor defines, following the patterns in the SDK repo.

@JeremyKuhne JeremyKuhne requested a review from a team as a code owner April 10, 2026 18:48
Copilot AI review requested due to automatic review settings April 10, 2026 18:48
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

Adds centralized OS/architecture detection to MSBuild’s build infrastructure so projects can conditionalize behavior based on the target platform (with VMR-friendly TargetOS handling) and expose platform-specific C# defines.

Changes:

  • Introduces eng/OSArch.props to compute HostOS/TargetOS, architecture properties, boolean targeting flags, and TARGET_WINDOWS/TARGET_UNIX defines for C#.
  • Switches src/Directory.Build.props to use $(TargetsWindows) (target platform) instead of IsOSPlatform('windows') (host platform) when deciding runtime output TFMs.
  • Adds an optional ShowPlatformProperties diagnostic target to print resolved platform properties during builds.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
Directory.Build.props Imports the new OS/arch detection props early so all projects can consume the computed properties.
eng/OSArch.props Implements OS/arch detection, target flags, and C# preprocessor defines (TARGET_WINDOWS, TARGET_UNIX).
src/Directory.Build.props Uses TargetsWindows to decide when to include net472 in RuntimeOutputTargetFrameworks.
Directory.Build.targets Adds a gated diagnostic target to print platform properties during build.

Comment thread eng/OSArch.props Outdated
Comment thread eng/OSArch.props Outdated
Comment thread eng/OSArch.props Outdated
Comment thread eng/OSArch.props Outdated
@JeremyKuhne
Copy link
Copy Markdown
Member Author

@ViktorHofer for some reason I missed your follow up changes. Updating.

…TARGET_UNIX)

This will facilitate conditionalizing OS specific code to reduce assembly size and make VMR integration easier. In particular, shifting to direct interop on Windows with CsWin32 will improve startup time and allow more code to run in AOT scenarios (notably in parts of the CLI).

Introduce centralized OS/architecture detection and platform-specific
C# preprocessor defines, following the patterns in the SDK repo.

Update per Viktor's feedback
Comment thread Directory.Build.targets
Comment on lines +61 to +69
<!-- Diagnostic target for verifying platform property resolution -->
<Target Name="ShowPlatformProperties"
BeforeTargets="Build"
Condition="'$(ShowPlatformProperties)' == 'true'">
<Message Importance="high" Text="HostOS = $(HostOS)" />
<Message Importance="high" Text="TargetOS = $(TargetOS)" />
<Message Importance="high" Text="BuildArchitecture = $(BuildArchitecture)" />
<Message Importance="high" Text="TargetArchitecture = $(TargetArchitecture)" />
</Target>
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 usually just use the inbuilt -getproperty command to get these property if we need them or look at a binlog.

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.

3 participants