Is package restore for C++ projects supposed to work with NuGEt 2.7?

Topics: General
Aug 26, 2013 at 9:21 AM
I had understood that 2.7 would fix the problem where you had to build C++ projects twice before the build succeeded (the restored package did not take effect until first build finished). However, on testing, I see that the same behavior still exists.

Did I misunderstand something about the 2.7 package restore changes? Is this behavior by design? Is there a plan to fix it in the future?

For reference, below is my build output of two consecutive builds of a blank project that improts a C++ library called BasePlatform.
c:\Windows\Microsoft.NET\Framework64\v4.0.30319>msbuild c:\Projects\ConsoleApplication2\ConsoleApplication2.sln
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18051]
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 26.08.2013 11:17:47.
Project "c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|x64".
Project "c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" (1) is building "c:\Projects\ConsoleApplication2\Cons
oleApplication2\ConsoleApplication2.vcxproj" (2) on node 1 (default targets).
RestorePackages:
  "c:\Projects\ConsoleApplication2\.nuget\NuGet.exe" install "c:\Projects\ConsoleApplication2\ConsoleApplication2\packa
  ges.config" -source ""  -NonInteractive -RequireConsent -solutionDir "c:\Projects\ConsoleApplication2\ "
  Restoring NuGet packages...
  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package
  Manager node and uncheck 'Allow NuGet to download missing packages'.
  Installing 'Axinom.BasePlatform 0.2.1'.
  Successfully installed 'Axinom.BasePlatform 0.2.1'.
InitializeBuildStatus:
  Creating "x64\Debug\ConsoleApplication2.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  All outputs are up-to-date.
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\AMD64\CL.exe /c /Zi /nologo /W3 /WX- /sdl /Od /D WIN32 /D
  _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yc"stdafx.h"
   /Fp"x64\Debug\ConsoleApplication2.pch" /Fo"x64\Debug\\" /Fd"x64\Debug\vc110.pdb" /Gd /TP /errorReport:queue stdafx.c
  pp
  stdafx.cpp
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\AMD64\CL.exe /c /Zi /nologo /W3 /WX- /sdl /Od /D WIN32 /D
  _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"stdafx.h"
   /Fp"x64\Debug\ConsoleApplication2.pch" /Fo"x64\Debug\\" /Fd"x64\Debug\vc110.pdb" /Gd /TP /errorReport:queue ConsoleA
  pplication2.cpp
  ConsoleApplication2.cpp
ConsoleApplication2.cpp(6): fatal error C1083: Cannot open include file: 'BasePlatform.h': No such file or directory [c
:\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj]
Done Building Project "c:\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj" (default target
s) -- FAILED.

Done Building Project "c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" (default targets) -- FAILED.


Build FAILED.

"c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" (default target) (1) ->
"c:\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj" (default target) (2) ->
(ClCompile target) ->
  ConsoleApplication2.cpp(6): fatal error C1083: Cannot open include file: 'BasePlatform.h': No such file or directory
[c:\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:12.85

c:\Windows\Microsoft.NET\Framework64\v4.0.30319>msbuild c:\Projects\ConsoleApplication2\ConsoleApplication2.sln
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18051]
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 26.08.2013 11:20:43.
Project "c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|x64".
Project "c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" (1) is building "c:\Projects\ConsoleApplication2\Cons
oleApplication2\ConsoleApplication2.vcxproj" (2) on node 1 (default targets).
RestorePackages:
  "c:\Projects\ConsoleApplication2\.nuget\NuGet.exe" install "c:\Projects\ConsoleApplication2\ConsoleApplication2\packa
  ges.config" -source ""  -NonInteractive -RequireConsent -solutionDir "c:\Projects\ConsoleApplication2\ "
  Restoring NuGet packages...
  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package
  Manager node and uncheck 'Allow NuGet to download missing packages'.
  All packages listed in packages.config are already installed.
InitializeBuildStatus:
  Touching "x64\Debug\ConsoleApplication2.unsuccessfulbuild".
ClCompile:
  All outputs are up-to-date.
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\AMD64\CL.exe /c /Ic:\Projects\ConsoleApplication2\packages
  \Axinom.BasePlatform.0.2.1\build\native\../..//build/native/include/ /Zi /nologo /W3 /WX- /sdl /Od /D _SCL_SECURE_NO_
  WARNINGS /D POCO_STATIC /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Z
  c:wchar_t /Zc:forScope /Yc"stdafx.h" /Fp"x64\Debug\ConsoleApplication2.pch" /Fo"x64\Debug\\" /Fd"x64\Debug\vc110.pdb"
   /Gd /TP /errorReport:queue stdafx.cpp
  stdafx.cpp
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\AMD64\CL.exe /c /Ic:\Projects\ConsoleApplication2\packages
  \Axinom.BasePlatform.0.2.1\build\native\../..//build/native/include/ /Zi /nologo /W3 /WX- /sdl /Od /D _SCL_SECURE_NO_
  WARNINGS /D POCO_STATIC /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Z
  c:wchar_t /Zc:forScope /Yu"stdafx.h" /Fp"x64\Debug\ConsoleApplication2.pch" /Fo"x64\Debug\\" /Fd"x64\Debug\vc110.pdb"
   /Gd /TP /errorReport:queue ConsoleApplication2.cpp
  ConsoleApplication2.cpp
Link:
  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\AMD64\link.exe /ERRORREPORT:QUEUE /OUT:"c:\Projects\Consol
  eApplication2\x64\Debug\ConsoleApplication2.exe" /INCREMENTAL /NOLOGO c:\Projects\ConsoleApplication2\packages\Axinom
  .BasePlatform.0.2.1\build\native\../..//build/native/lib/x64\Debug\BasePlatform.PC.Debug.lib kernel32.lib user32.lib
  gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
  /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"c:\Projects\ConsoleApplicati
  on2\x64\Debug\ConsoleApplication2.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"c:\Projects\Consol
  eApplication2\x64\Debug\ConsoleApplication2.lib" /MACHINE:X64 x64\Debug\ConsoleApplication2.obj
  x64\Debug\stdafx.obj
  ConsoleApplication2.vcxproj -> c:\Projects\ConsoleApplication2\x64\Debug\ConsoleApplication2.exe
FinalizeBuildStatus:
  Deleting file "x64\Debug\ConsoleApplication2.unsuccessfulbuild".
  Touching "x64\Debug\ConsoleApplication2.lastbuildstate".
Done Building Project "c:\Projects\ConsoleApplication2\ConsoleApplication2\ConsoleApplication2.vcxproj" (default target
s).

Done Building Project "c:\Projects\ConsoleApplication2\ConsoleApplication2.sln" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.51
Aug 29, 2013 at 11:59 PM
For the NuGet 2.7 package restore approach, you need to get an updated version of nuget.exe, and then run the nuget.exe restore command ahead of calling msbuild. Essentially, we are abandoning the MSBuild-integrated approach for package restore.

Inside Visual Studio, we call the equivalent of nuget.exe restore automatically (unless the project has enabled the MSBuild-integrated restore approach).

Here's some more info:
http://docs.nuget.org/docs/reference/package-restore

There's also a pending addition to the docs for migrating from the MSBuild-integrated restore to the automatic restore. Here's that pending document addition:
https://github.com/craigajohnson/NuGetDocs/blob/6e601bd59f484c21ef6c302c5696611359daf2f8/site/Docs/Workflows/Migrating-to-Automatic-Package-Restore.markdown