You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps流水线NuGet还原无法找到nlohmann.json求助

问题:C++ .vcxproj项目NuGet还原提示无包可还原

我正在创建流水线构建C++ .vcxproj项目,该项目在Visual Studio中可正常构建,但执行NuGet restore时提示Nothing to do. This project does not specify any packages for NuGet to restore.

packages.config 文件内容

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="nlohmann.json" version="3.11.2" targetFramework="native" />
</packages>

NuGet还原输出日志

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
解决方案

针对原生C++项目的NuGet还原问题,可尝试以下几种解决办法:

  • 改用MSBuild命令执行还原
    原生C++项目推荐直接使用MSBuild的/t:Restore参数,替换流水线中的NuGet restore任务为如下命令:

    msbuild D:\a\1\s\GenericEngine\GenericEngine.vcxproj /t:Restore /p:RestorePackagesConfig=true
    

    该参数会明确读取packages.config中的包信息完成还原。

  • 确认项目文件与packages.config的关联
    检查.vcxproj文件中是否包含NuGet包的导入配置段,确保NuGet能识别到packages.config:

    <Import Project="..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets" Condition="Exists('..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" />
    <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
      <PropertyGroup>
        <ErrorText>引用的NuGet程序包缺失,请还原NuGet程序包。</ErrorText>
      </PropertyGroup>
      <Error Condition="!Exists('..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets'))" />
    </Target>
    

    若没有这段配置,可手动添加,或在Visual Studio中重新安装一次nlohmann.json包,让VS自动生成关联配置。

  • 指定packages.config路径执行还原
    调整NuGet命令,直接指向packages.config文件而非项目文件:

    nuget restore D:\a\1\s\GenericEngine\packages.config -PackagesDirectory D:\a\1\s\packages
    

内容的提问来源于stack exchange,提问作者eugen_nw

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 00:50:09