Repository navigation
PlatformTarget is not set when Platform is "arm64" (MSBuild) #15434
Description
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=x64dotnet build -p:Platform=x86dotnet build -p:Platform=armdotnet 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
akoeplinger commentedon Apr 6, 2023
This was fixed by #24996
Remove PreviouslySourceBuiltPackageVersions cleanup workaround (#15434)