azure-devopsnugetnlohmann-json

nlohmann.json - "NuGet restore" in Azure DevOps pipeline cannot find it


I wonder if anyone was successful with this task. I'm working on creating a pipeline to build a C++ .vcxproj. The project builds great from within Visual Studio. The packages.config file is below and further below is the output of "NuGet restore".

Thanks very much, eugen

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="nlohmann.json" version="3.11.2" targetFramework="native" />
</packages>
Starting: NuGet restore
==============================================================================
Task         : NuGet
Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version      : 2.238.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/nuget
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Detected NuGet version 6.6.1.2 / 6.6.1+f4f3bb12a1ccbb974bca9b115a7b7291a7d6fb39.f4f3bb12a1ccbb974bca9b115a7b7291a7d6fb39
C:\hostedtoolcache\windows\NuGet\6.6.1\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile D:\a\1\Nuget\tempNuGet_43856.config
Package source with Name: NuGetOrg added successfully.
C:\hostedtoolcache\windows\NuGet\6.6.1\x64\nuget.exe restore D:\a\1\s\GenericEngine\GenericEngine.vcxproj -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\Nuget\tempNuGet_43856.config
NuGet Version: 6.6.1.2
MSBuild P2P timeout [ms]: 120000
MSBuild auto-detection: using msbuild version '17.12.12.57101' from 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin\msbuild.exe "C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\5fye53rd.au3.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\j5e05orb.ouy.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:DisableCheckingDuplicateNuGetItems="True" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\6.6.1\x64\nuget.exe" /p:RestoreConfigFile="D:\a\1\Nuget\tempNuGet_43856.config"

Nothing to do. This project does not specify any packages for NuGet to restore.
Finishing: NuGet restore

Solution

  • Nothing to do. This project does not specify any packages for NuGet to restore

    The cause of the issue could be that the Nuget Restore task cannot read the pacakge.config file.

    To solve this issue, you can refer to the following two methods:

    Method1: you can move the pacakge.config file to the same path of the GenericEngine.vcxproj.

    For example: File Structure

    GenericEngine
      - pacakge.config
      - GenericEngine.vcxproj
    

    Then when using the Nuget restore task, you need to define the Destination directory in Nuget Restore task.

    You can check the package path in the .vcxproj file and set Destination directory.

    For example:

    .vcxproj

     <Import Project="..\packages\boost.1.71.0.0\build\boost.targets" Condition="Exists('..\packages\boost.1.71.0.0\build\boost.targets')" />
    

    Nuget Restore Task: Set ..\packages in Destination directory

    steps:
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: Examples/Examples.vcxproj
        restoreDirectory: '..\packages'
    

    Method2: you can use pacakge.config file to restore Nuget Pacakges. And set Destination directory.

    For example:

    steps:
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: Examples/packages.config
        restoreDirectory: '..\packages'
    

    Result:

    enter image description here