DotnetSdkVariables-check.cmake 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. set(files foo.csproj bar.csproj baz.csproj)
  2. set(inLib1 FALSE)
  3. set(dotnetSdkInLib1 FALSE)
  4. set(inLib2 FALSE)
  5. set(dotnetSdkWebInLib2 FALSE)
  6. set(inLib3 FALSE)
  7. set(classicProjInLib3 FALSE)
  8. foreach(file ${files})
  9. set(csProjectFile ${RunCMake_TEST_BINARY_DIR}/${file})
  10. if(NOT EXISTS "${csProjectFile}")
  11. set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
  12. return()
  13. endif()
  14. file(STRINGS "${csProjectFile}" lines)
  15. foreach(line IN LISTS lines)
  16. if(NOT inLib1)
  17. if(line MATCHES "<Project Sdk=\"Microsoft\.NET\.Sdk\">")
  18. set(dotnetSdkInLib1 TRUE)
  19. set(inLib1 TRUE)
  20. endif()
  21. elseif(NOT inLib2)
  22. if(line MATCHES "<Project Sdk=\"Microsoft\.NET\.Sdk\.Web\">")
  23. set(dotnetSdkWebInLib2 TRUE)
  24. set(inLib2 TRUE)
  25. endif()
  26. elseif(NOT inLib3)
  27. if(line MATCHES "<Project DefaultTargets=\"Build\" ToolsVersion=\"")
  28. set(classicProjInLib3 TRUE)
  29. set(inLib3 TRUE)
  30. endif()
  31. endif()
  32. endforeach()
  33. endforeach()
  34. if(NOT dotnetSdkInLib1)
  35. set(RunCMake_TEST_FAILED ".Net SDK not set correctly.")
  36. endif()
  37. if(NOT dotnetSdkWebInLib2)
  38. set(RunCMake_TEST_FAILED ".Net Web SDK not set correctly.")
  39. endif()
  40. if(NOT classicProjInLib3)
  41. set(RunCMake_TEST_FAILED "Empty DOTNET_SDK doesn't build Classic project.")
  42. endif()