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
This commit is contained in:
Calum Robinson
2024-09-11 10:30:07 +01:00
parent bc5f3ed586
commit 3283ef47d1
4 changed files with 13 additions and 4 deletions

View File

@@ -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"),

View File

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

View File

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

View File

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