Skip to content

PlatformTarget is not set when Platform is "arm64" (MSBuild) #15434

Closed

Description

@kpreisser

Hi!

I noticed that when building .NET 5 projects on Windows and using one of the values x86, x64, arm (or ARM) for Platform (MSBuild property), the PlatformTarget property seems to automatically be set by the SDK to the Platform value. However, when using arm64 (or ARM64), it doesn't seem to get set, and it seems to assume AnyCPU (so the copied apphost EXE is not necessarily of the specified architecture).

For example:

  • Install .NET SDK 5.0.102 (x64) on Windows 10 Version 20H2 x64
  • Create a new .NET 5 project with dotnet new console
  • Add the following target to the project.csproj:
    <Target Name="PostBuild" AfterTargets="PostBuildEvent">
      <Message Importance="high" Text="Platform: '$(Platform)', PlatformTarget: '$(PlatformTarget)', RID: '$(RuntimeIdentifier)'" />
    </Target>
  • Run the following commands:
    • dotnet build -p:Platform=x64
    • dotnet build -p:Platform=x86
    • dotnet build -p:Platform=arm
    • dotnet build -p:Platform=arm64

It produces the following output from the target:

  • Platform: 'x64', PlatformTarget: 'x64', RID: ''
  • Platform: 'x86', PlatformTarget: 'x86', RID: ''
  • Platform: 'arm', PlatformTarget: 'ARM', RID: ''
  • Platform: 'arm64', PlatformTarget: '', RID: ''

Notice that when Platform is arm64, PlatformTarget is not set. This seems to cause the SDK using the apphost with the SDK architecture (x64) instead of the specified platform (arm64). When we set the PlatformTarget manually to arm64, then the arm64 apphost is used.

This also seems to be the case when specifying RuntimeIdentifiers, where for win-arm64 the PlatformTarget is AnyCPU but e.g. for win-x64 it is x64.

In Microsoft.NET.Sdk.props, I can see the following condition that sets the PlatformTarget based on Platform:

<PropertyGroup>
<_PlatformWithoutConfigurationInference>$(Platform)</_PlatformWithoutConfigurationInference>
</PropertyGroup>
<PropertyGroup Condition=" '$(_PlatformWithoutConfigurationInference)' == 'x64' ">
<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(_PlatformWithoutConfigurationInference)' == 'x86' ">
<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(_PlatformWithoutConfigurationInference)' == 'ARM' ">
<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">ARM</PlatformTarget>
</PropertyGroup>

Notice that it checks Platform for x86, x64, and ARM, but not for ARM64.

Is this intended behavior?
Thank you!

Activity

  1. ghost added
    untriagedRequest triage from a team member
    on Jan 21, 2021
  2. added and removed
    untriagedRequest triage from a team member
    on Feb 3, 2021
  3. akoeplinger commented on Apr 6, 2023

    @akoeplinger
    Member

    This was fixed by #24996

  4. added theissue type on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions