Add CsWin32PlatformTarget to generate arch-specific APIs in AnyCPU projects - #1835
Merged
Jevan Saks (jevansaks) merged 3 commits intoOct 1, 2026
Merged
Conversation
Co-authored-by: jevansaks <20667023+jevansaks@users.noreply.github.com>
Co-authored-by: jevansaks <20667023+jevansaks@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add capability to specify API architecture in settings json
Add Oct 1, 2026
CsWin32PlatformTarget to generate arch-specific APIs in AnyCPU projects
Jevan Saks (jevansaks)
approved these changes
Oct 1, 2026
Jevan Saks (jevansaks)
marked this pull request as ready for review
October 1, 2026 18:13
Sergio Pedri (Sergio0694)
approved these changes
Oct 1, 2026
Jevan Saks (jevansaks)
deleted the
copilot/specify-api-architecture-settings
branch
October 1, 2026 18:46
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.
AnyCPU projects such as WinForms cannot generate arch-specific Win32 APIs (Pack=1 structs,
Get/SetWindowLongPtr, …), even when they know one architecture's definitions are fine for their use. This PR adds an MSBuild property that overrides the architecture used to select those APIs. The compiled assembly stays AnyCPU.Changes
build_property.CsWin32PlatformTargetand generates with that platform by passing the compilation to the generator viaWithOptions(...WithPlatform(...)). No public API change.AnyCPU,x86,x64,arm64. Any other value raises the new error PInvoke014 and nothing is generated.PlatformTargetor<CsWin32PlatformTarget>.Module.*wildcard requests still silently skip arch-specific APIs.CsWin32RunAsBuildTask)$(CsWin32PlatformTarget)to the generator, falling back to$(PlatformTarget).CsWin32Generator)PlatformIncompatibleExceptions, e.g. when the requested API depends on an arch-specific type.CsWin32PlatformTargetadded as aCompilerVisibleProperty.AnalyzerReleases.Unshipped.mdupdated: PInvoke005 is now Error, and PInvoke014 is added.ArchSpecificAPIs.mdhas a new section on the property, with a warning that the user is responsible for layout correctness on other architectures.Reviewer notes
CsWin32PlatformTargetdoes not invalidateGenerateCsWin32Code's incremental Inputs/Outputs, so the generator won't re-run.PlatformTargetalready behaves the same way, so this PR leaves it unaddressed.