Browse Source

VS: Fix DOTNET_SDK builds when no VS_PACKAGE_REFERENCES set

nuget restore always needs to be run for the new DOTNET_SDK style
projects, even when VS_PACKAGE_REFERENCES is empty.

Fixes: #23405
Calum Robinson 1 year ago
parent
commit
3283ef47d1

+ 3 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -5924,7 +5924,8 @@ void cmVisualStudio10TargetGenerator::UpdateCache()
 {
   std::vector<std::string> packageReferences;
 
-  if (this->GeneratorTarget->HasPackageReferences()) {
+  if (this->GeneratorTarget->IsDotNetSdkTarget() ||
+      this->GeneratorTarget->HasPackageReferences()) {
     // Store a cache entry that later determines, if a package restore is
     // required.
     this->GeneratorTarget->Makefile->AddCacheDefinition(
@@ -5941,7 +5942,7 @@ void cmVisualStudio10TargetGenerator::UpdateCache()
     OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
 
     for (cmGeneratorTarget const* dt : depends) {
-      if (dt->HasPackageReferences()) {
+      if (dt->IsDotNetSdkTarget() || dt->HasPackageReferences()) {
         this->GeneratorTarget->Makefile->AddCacheDefinition(
           cmStrCat(this->GeneratorTarget->GetName(),
                    "_REQUIRES_VS_PACKAGE_RESTORE"),

+ 1 - 2
Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake

@@ -24,9 +24,8 @@ function(runCmakeAndBuild CASE)
   file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
   file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
   run_cmake(${CASE})
-  set(build_flags /restore)
-  run_cmake_command(${CASE}-build ${CMAKE_COMMAND} --build . -- ${build_flags})
   run_cmake_command(${CASE}-build ${CMAKE_COMMAND} --build .)
 endfunction()
 
 runCmakeAndBuild(VsDotnetSdkCustomCommandsTarget)
+runCmakeAndBuild(VsDotnetSdkNugetRestore)

+ 1 - 0
Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore-build-stdout.txt

@@ -0,0 +1 @@
+Determining projects to restore

+ 8 - 0
Tests/RunCMake/VsDotnetSdk/VsDotnetSdkNugetRestore.cmake

@@ -0,0 +1,8 @@
+enable_language(CSharp)
+if(NOT CMAKE_CSharp_COMPILER)
+    return()
+endif()
+
+set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
+
+add_executable(foo csharponly.cs lib1.cs)