Browse Source

Merge topic 'VS-include_external_msproject-CSharp-targets-references'

c7aa3bdefc Tests/include_external_msproject: Check C# project reference
65b58b0316 VS Generator: Properly reference included external C# projects

Acked-by: Kitware Robot <[email protected]>
Merge-request: !6123
Brad King 4 years ago
parent
commit
40a7572e4f

+ 3 - 4
Source/cmVisualStudio10TargetGenerator.cxx

@@ -4253,11 +4253,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
     if (dt->IsCSharpOnly() || cmHasLiteralSuffix(path, "csproj")) {
       e2.Element("SkipGetTargetFrameworkProperties", "true");
     }
-
     // Don't reference targets that don't produce any output.
-    if (this->Configurations.empty() ||
-        dt->GetManagedType(this->Configurations[0]) ==
-          cmGeneratorTarget::ManagedType::Undefined) {
+    else if (this->Configurations.empty() ||
+             dt->GetManagedType(this->Configurations[0]) ==
+               cmGeneratorTarget::ManagedType::Undefined) {
       e2.Element("ReferenceOutputAssembly", "false");
       e2.Element("CopyToOutputDirectory", "Never");
     }

+ 1 - 0
Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake

@@ -8,4 +8,5 @@ run_cmake(CustomConfig)
 
 if(RunCMake_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])")
   run_cmake(SkipGetTargetFrameworkProperties)
+  run_cmake(VSCSharpReference)
 endif()

+ 36 - 0
Tests/RunCMake/include_external_msproject/VSCSharpReference-check.cmake

@@ -0,0 +1,36 @@
+file(READ "${RunCMake_TEST_BINARY_DIR}/internal.vcxproj" all_build)
+
+string(REGEX MATCH
+  "<ProjectReference.Include=.external.csproj.>.*</ProjectReference>"
+  ProjectReference
+  ${all_build}
+)
+
+if(ProjectReference STREQUAL "")
+  set(RunCMake_TEST_FAILED "${test} is being set unexpectedly.")
+else()
+  string(REGEX MATCH
+    "<ReferenceOutputAssembly>.*</ReferenceOutputAssembly>"
+    ReferenceOutputAssembly
+    ${ProjectReference}
+  )
+
+  if(NOT ReferenceOutputAssembly STREQUAL "")
+    string(REPLACE
+      "<ReferenceOutputAssembly>"
+      ""
+      ReferenceOutputAssemblyValue
+      ${ReferenceOutputAssembly}
+    )
+    string(REPLACE
+      "</ReferenceOutputAssembly>"
+      ""
+      ReferenceOutputAssemblyValue
+      ${ReferenceOutputAssemblyValue}
+    )
+
+    if(ReferenceOutputAssemblyValue MATCHES "[Fa][Ll][Ss][Ee]")
+      set(RunCMake_TEST_FAILED "Referenced C# project with ReferenceOutputAssembly set to false.")
+    endif()
+  endif()
+endif()

+ 10 - 0
Tests/RunCMake/include_external_msproject/VSCSharpReference.cmake

@@ -0,0 +1,10 @@
+project(VSCSharpReference)
+
+include_external_msproject(external external.csproj)
+
+add_executable(internal
+    main.cpp
+)
+add_dependencies(internal
+    external
+)