Add platform-specific build infrastructure (TargetOS, TARGET_WINDOWS…)#13523
Draft
JeremyKuhne wants to merge 1 commit intodotnet:mainfrom
Draft
Add platform-specific build infrastructure (TargetOS, TARGET_WINDOWS…)#13523JeremyKuhne wants to merge 1 commit intodotnet:mainfrom
JeremyKuhne wants to merge 1 commit intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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.propsto computeHostOS/TargetOS, architecture properties, boolean targeting flags, andTARGET_WINDOWS/TARGET_UNIXdefines for C#. - Switches
src/Directory.Build.propsto use$(TargetsWindows)(target platform) instead ofIsOSPlatform('windows')(host platform) when deciding runtime output TFMs. - Adds an optional
ShowPlatformPropertiesdiagnostic 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. |
ViktorHofer
reviewed
Apr 10, 2026
ViktorHofer
reviewed
Apr 10, 2026
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
ViktorHofer
reviewed
Apr 13, 2026
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> |
Member
There was a problem hiding this comment.
We usually just use the inbuilt -getproperty command to get these property if we need them or look at a binlog.
ViktorHofer
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.