Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

PlatformTarget is a legacy .NET Framework setting that has no effect in modern .NET. Users explicitly setting it to non-AnyCPU values (x64, x86, arm, arm64) should be guided to remove this customization.

Changes

  • New warning NETSDK1235: Warns when PlatformTarget is explicitly set to a non-AnyCPU value in .NETCoreApp projects
  • Target _CheckForNonAnyCPUPlatformTarget: Only fires when user explicitly sets the property (not when SDK infers it from RuntimeIdentifier)
  • Unit tests: Validates warning appears for explicit non-AnyCPU values and does not appear for AnyCPU

Example

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <PlatformTarget>x64</PlatformTarget> <!-- NETSDK1235 warning -->
  </PropertyGroup>
</Project>

Output:

warning NETSDK1235: Setting the PlatformTarget property to 'x64' is not recommended 
for modern .NET applications. The PlatformTarget property is a legacy setting from 
.NET Framework and has no effect in modern .NET. Consider removing PlatformTarget 
or setting it to 'AnyCPU'.

No warning is issued when:

  • PlatformTarget is AnyCPU
  • PlatformTarget is not set or inferred from RuntimeIdentifier
  • Target framework is .NET Framework
Original prompt

This section details on the original issue you should resolve

<issue_title>Flag usage of non-AnyCPU values for PlatformTarget in modern .NET applications</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.

The PlatformTarget field (and therefore Platform in MSbuild) only applies to .NET Framework and doesn't apply to modern .NET applications. For these applications, Platform can (should) always be AnyCPU. We should guide users to removing customizations to this property for projects that do not need it.

From Jan Kotas in #42344:

PlatformTarget is left-over from .NET Framework. (PlatformTarget can only represent architectures that .NET Framework targets. It does not represent full range of platforms that .NET Core can target.)

If you are targeting current .NET, building everything as AnyCPU (ie hardcoding PlatformTarget to AnyCPU) all the time should work just fine. It is what we are doing in dotnet/runtime repo. We hardcode PlatformTarget to AnyCPU, even for platform-specific binaries.</issue_description>

Comments on the Issue (you are @copilot in this section)

@jkotas Also, you may want to stop inferring the `PlatformTarget` in the SDK when targeting modern .NET applications:

<!-- Determine PlatformTarget (if not already set) from runtime identifier. -->
<Choose>
<When Condition="'$(PlatformTarget)' != '' or '$(RuntimeIdentifier)' == ''" />
<When Condition="$(RuntimeIdentifier.EndsWith('-x86')) or $(RuntimeIdentifier.Contains('-x86-'))">
<PropertyGroup>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
</When>
<When Condition="$(RuntimeIdentifier.EndsWith('-x64')) or $(RuntimeIdentifier.Contains('-x64-'))">
<PropertyGroup>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
</When>
<When Condition="$(RuntimeIdentifier.EndsWith('-arm')) or $(RuntimeIdentifier.Contains('-arm-'))">
<PropertyGroup>
<PlatformTarget>arm</PlatformTarget>
</PropertyGroup>
</When>
<When Condition="$(RuntimeIdentifier.EndsWith('-arm64')) or $(RuntimeIdentifier.Contains('-arm64-'))">
<PropertyGroup>
<PlatformTarget>arm64</PlatformTarget>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
</Otherwise>
</Choose>
</comment_new>
<comment_new>@baronfel
@jkotas this issue is for an MSBuild BuildCheck for usage in customer projects, so I extracted your comment to a new issue for the SDK to stop setting it in the first place.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 4, 2025 23:17
Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove non-AnyCPU values for PlatformTarget in .NET Add NETSDK1235 warning for non-AnyCPU PlatformTarget in modern .NET Dec 4, 2025
Copilot AI requested a review from agocke December 4, 2025 23:25
Copilot finished work on behalf of agocke December 4, 2025 23:25
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.

Flag usage of non-AnyCPU values for PlatformTarget in modern .NET applications

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.