VS: Consistent handling of PlatformTarget property for managed .NET projects
This issue is a break out from a former merge request, see !7249 (closed)
The target platform information provides, in classic and SDK-style Visual Studio projects, which target architecture shall be used for binary output.
Visual Studio 2019 offers for managed .NET projects x86
, x64
, ARM32
, ARM64
or AnyCPU
in SDK-style projects and x86
, x64
and Any CPU
in classic projects.
In addition, it is possible if Any CPU
is selected (no matter if it's a classic or SDK style project) to set a flag called <Prefer32Bit>true/false</Prefer32Bit>
.
Native projects like C/C++ are using partly the same target platform identifier. Obviously, there is no Any CPU, but x86 or x64.
The classic project generator extracts the information about the target platform from the /platform:xxx
compiler flag or uses the current developer platform identifier by default. This applies also for managed projects for .NET environments. Means, if you are executing CMake on a x64 computer and haven't set additional flags, you are getting a x64 bit target platform by default.
As of now, the SDK-style project generator cannot to set the <PlatformTarget>
property at all. The question is, how to implement it for the new generator and also harmonize the handling for CMake users.
Visual Studio itself prefers always Any CPU
if new projects are created or no information is provided. I think that would be the first rule to apply also in CMake.
As we (@brad.king, @bhardwajs, @rainersigwald) discussed, VS_PLATFORM_TARGET
and VS_DOTNET_PLATFORM_TARGET
have some drawbacks. Maybe the property should mention that it applies only for managed .NET projects. So we can keep all native platform settings as they are.
Let’s say we would have VS_MANAGED_NET_PROJECT_PLATFORM_TARGET
with the following options to set:
- x86
- x64
- ARM32
- ARM64
- AnyCPU
- AnyCPU_Prefer32Bit
One last point, during my testing I noticed that there can be a project global <PlatformTarget>
and a profile based <PlatformTarget>
which offers the option to handle build targets like Debug_x86 and Debug_x64. For my feeling this is very complex and even the UI in Visual Studio 2022 strikes here (drop down selection is not working properly). I would leave that out for the time being and keep the project global property in focus.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
...
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
...
<PlatformTarget>x64</PlatformTarget>
...
Any comments on that?