VS: Fix SLNs for DOTNET_SDK targets with VS_GLOBAL_PlatformTarget

By default, .NET SDK-style projects build for "Any CPU", so we generate
solution files accordingly.  Although CMake does not model per-target
architectures, some projects set the `VS_GLOBAL_PlatformTarget` property
on `DOTNET_SDK` targets in order to compile for a specific architecture.
Fix generated solution files to account for the architecture override.

Issue: #23513
This commit is contained in:
Jelle
2025-09-25 06:16:51 -04:00
committed by Brad King
parent 05a3f4a30d
commit 4ebedf246d
6 changed files with 82 additions and 6 deletions
+13 -6
View File
@@ -977,12 +977,19 @@ cm::VS::Solution cmGlobalVisualStudioGenerator::CreateSolution(
project->TypeId = Solution::Project::TypeIdDefault;
}
project->Platform =
// On VS 19 and above, always map .NET SDK projects to "Any CPU".
(gt->IsDotNetSdkTarget() && this->Version >= VSVersion::VS16 &&
!cmGlobalVisualStudioGenerator::IsReservedTarget(gt->GetName()))
? "Any CPU"
: solution.Platform;
if (gt->IsDotNetSdkTarget() &&
!cmGlobalVisualStudioGenerator::IsReservedTarget(gt->GetName())) {
cmValue platformTarget = gt->GetProperty("VS_GLOBAL_PlatformTarget");
if (!platformTarget.IsEmpty()) {
project->Platform = *platformTarget;
} else {
project->Platform =
// On VS 16 and above, always map .NET SDK projects to "Any CPU".
this->Version >= VSVersion::VS16 ? "Any CPU" : solution.Platform;
}
} else {
project->Platform = solution.Platform;
}
// Add solution-level dependencies.
TargetDependSet const& depends = this->GetTargetDirectDepends(gt);