Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kpreisser opened this issue Jan 21, 2021 · 2 comments
Closed

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

kpreisser opened this issue Jan 21, 2021 · 2 comments
Assignees
Labels

Comments

@kpreisser
Copy link

kpreisser commented Jan 21, 2021

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!

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Jan 21, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@akoeplinger
Copy link
Member

This was fixed by #24996

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants