瀏覽代碼

VS: Fix SLNX generation so .NET Core projects build in the IDE

Extend commit 46b0202ce0 (VS: Fix SLNX generation so CSharp projects
build in the IDE, 2025-10-23, v4.2.0-rc2~26^2) to cover .NET Core
projects.

Fixes: #27524
Brad King 2 天之前
父節點
當前提交
0c97912756
共有 2 個文件被更改,包括 14 次插入3 次删除
  1. 13 3
      Source/cmVSSolution.cxx
  2. 1 0
      Tests/RunCMake/include_external_msproject/ProjType-check-slnx.cmake

+ 13 - 3
Source/cmVSSolution.cxx

@@ -311,6 +311,18 @@ void WriteSln(std::ostream& sln, Solution const& solution)
 }
 
 namespace {
+
+bool NeedExplicitProjectPlatform(cm::string_view typeId)
+{
+  // Some projects do not build interactively in the VS IDE unless they
+  // have an explicit platform, even if it matches the SLN platform.
+  if (typeId == Solution::Project::TypeIdCSharp ||
+      typeId == Solution::Project::TypeIdDotNetCore) {
+    return true;
+  }
+  return false;
+}
+
 void WriteSlnxSolutionConfigurationPlatforms(cmXMLElement& xmlParent,
                                              Solution const& solution)
 {
@@ -353,9 +365,7 @@ void WriteSlnxProject(cmXMLElement& xmlParent, Solution const& solution,
     }
   }
   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) {
+      NeedExplicitProjectPlatform(project.TypeId)) {
     cmXMLElement(xmlProject, "Platform")
       .Attribute("Project", project.Platform);
   }

+ 1 - 0
Tests/RunCMake/include_external_msproject/ProjType-check-slnx.cmake

@@ -26,6 +26,7 @@ RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/ProjType.slnx" [[
   </Project>
   <Project Path="DotNetCore.project" Type="9a19103f-16f7-4668-be54-9a1e7a4f7556" Id="[0-9a-f-]+">
     <BuildDependency Project="ZERO_CHECK\.vcxproj"/>
+    <Platform Project="[^"]+"/>
   </Project>
   <Project Path="JScript.project" Type="262852c6-cd72-467d-83fe-5eeb1973a190" Id="[0-9a-f-]+">
     <BuildDependency Project="ZERO_CHECK\.vcxproj"/>