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
This commit is contained in:
Brad King
2025-10-23 09:56:53 -04:00
parent 50ea94ad97
commit 46b0202ce0
3 changed files with 6 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -19,5 +19,6 @@ RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/VsDotnetSdkTargetPlatform.slnx"
<Project Path="ZERO_CHECK\.vcxproj" Id="[0-9a-f-]+"/>
<Project Path="foo\.csproj" Id="[0-9a-f-]+">
<BuildDependency Project="ZERO_CHECK\.vcxproj"/>
<Platform Project="[^"]+"/>
</Project>
</Solution>$]])

View File

@@ -26,6 +26,7 @@ RunCMake_check_slnx("${RunCMake_TEST_BINARY_DIR}/AutoType.slnx" [[
<Project Path="ZERO_CHECK\.vcxproj" Id="[0-9a-f-]+"/>
<Project Path="external\.csproj" Id="[0-9a-f-]+">
<BuildDependency Project="ZERO_CHECK.vcxproj"/>
<Platform Project="[^"]+"/>
</Project>
<Project Path="external\.dbproj" Id="[0-9a-f-]+">
<BuildDependency Project="ZERO_CHECK.vcxproj"/>