From 46b0202ce04576d35b08afe6eefb58f69716f9e2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 23 Oct 2025 09:56:53 -0400 Subject: [PATCH] VS: Fix SLNX generation so CSharp projects build in the IDE Add an explicit solution-level per-project `Platform` for `.csproj` projects even if it is the same as the solution-wide `Platform`. Otherwise the VS IDE skips building it. Fixes: #27330 --- Source/cmVSSolution.cxx | 5 ++++- .../VsDotnetSdk/VsDotnetSdkTargetPlatform-check-slnx.cmake | 1 + .../include_external_msproject/AutoType-check-slnx.cmake | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/cmVSSolution.cxx b/Source/cmVSSolution.cxx index 2fc6fca630..7b0c04e67b 100644 --- a/Source/cmVSSolution.cxx +++ b/Source/cmVSSolution.cxx @@ -331,7 +331,10 @@ void WriteSlnxProject(cmXMLElement& xmlParent, Solution const& solution, .Attribute("Solution", cmStrCat(solution.Configs[i], "|*")); } } - if (project.Platform != solution.Platform) { + if (project.Platform != solution.Platform || + // C# projects do not build interactively in the VS IDE unless they + // have an explicit platform, even if it matches the SLN platform. + project.TypeId == Solution::Project::TypeIdCSharp) { cmXMLElement(xmlProject, "Platform") .Attribute("Project", project.Platform); } diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkTargetPlatform-check-slnx.cmake b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkTargetPlatform-check-slnx.cmake index 7ab421de7b..f1f7492c1c 100644 --- a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkTargetPlatform-check-slnx.cmake +++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkTargetPlatform-check-slnx.cmake @@ -19,5 +19,6 @@ RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/VsDotnetSdkTargetPlatform.slnx" + $]]) diff --git a/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake b/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake index 4a4a1cb1b2..560c9c0229 100644 --- a/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake +++ b/Tests/RunCMake/include_external_msproject/AutoType-check-slnx.cmake @@ -26,6 +26,7 @@ RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/AutoType.slnx" [[ +