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

Azure DevOps中.NET Core应用dotnet restore任务失败原因排查

问题解决:NuGet版本字符串格式错误导致Azure Pipeline还原失败

错误核心原因

报错明确指出'6.1.6,6.2.3' is not a valid version string,这是因为NuGet不支持用逗号直接分隔多个版本号,这种写法不符合NuGet版本范围的语法规范。

解决步骤

  • 打开项目中的WebApp.csproj文件,搜索包含版本值6.1.6,6.2.3的<PackageReference>节点
  • 根据实际需求修正版本格式:
    • 如果需要允许安装6.1.6或6.2.3这两个特定版本,使用NuGet的逻辑或语法:
      <PackageReference Include="YourPackageName" Version="[6.1.6] || [6.2.3]" />
      
    • 如果是输入错误,只需要单一版本,直接改为单个版本号:
      <PackageReference Include="YourPackageName" Version="6.2.3" />
      
  • 本地执行dotnet restore验证修复成功后,提交代码并重新运行Azure Pipeline

原始错误日志

2023-02-16T17:02:26.7325011Z      1>C:\hostedtoolcache\windows\dotnet\sdk\6.0.406\NuGet.targets(132,5): error : '6.1.6,6.2.3' is not a valid version string. [D:\a\1\s\WebApp\WebApp.csproj]
2023-02-16T17:02:26.7944327Z          System.ArgumentException: '6.1.6,6.2.3' is not a valid version string.
2023-02-16T17:02:26.7945294Z             at NuGet.Versioning.VersionRange.Parse(String value, Boolean allowFloating)
2023-02-16T17:02:26.7946303Z             at NuGet.Versioning.VersionRange.Parse(String value)
2023-02-16T17:02:26.7947172Z             at NuGet.Commands.MSBuildRestoreUtility.AddPackageReferences(PackageSpec spec, IEnumerable`1 items, Boolean isCpvmEnabled)
2023-02-16T17:02:26.7948010Z             at NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec(IEnumerable`1 items)
2023-02-16T17:02:26.7948973Z             at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
2023-02-16T17:02:26.7949761Z             at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
2023-02-16T17:02:26.7950412Z             at NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec(IEnumerable`1 items)
2023-02-16T17:02:26.7951037Z             at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
2023-02-16T17:02:26.7951399Z        Done executing task "RestoreTask" -- FAILED.
2023-02-16T17:02:26.7951774Z      1>Done building target "Restore" in project "WebApp.csproj" -- FAILED.
2023-02-16T17:02:26.7961752Z      1>Done Building Project "D:\a\1\s\WebApp\WebApp.csproj" (Restore target(s)) -- FAILED.
2023-02-16T17:02:26.8025517Z 
2023-02-16T17:02:26.8026122Z Build FAILED.
2023-02-16T17:02:26.8029367Z 
2023-02-16T17:02:26.8030306Z        "D:\a\1\s\WebApp\WebApp.csproj" (Restore target) (1) -
2023-02-16T17:02:26.8030690Z        (Restore target) -> 
2023-02-16T17:02:26.8031149Z          C:\hostedtoolcache\windows\dotnet\sdk\6.0.406\NuGet.targets(132,5): error : '6.1.6,6.2.3' is not a valid version string. [D:\a\1\s\WebApp\WebApp.csproj]
2023-02-16T17:02:26.8031458Z 
2023-02-16T17:02:26.8031674Z     0 Warning(s)
2023-02-16T17:02:26.8031958Z     1 Error(s)
2023-02-16T17:02:26.8033465Z 
2023-02-16T17:02:26.8034195Z Time Elapsed 00:00:00.91
2023-02-16T17:02:26.8611133Z ##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
2023-02-16T17:02:26.8625609Z ##[error]Packages failed to restore
2023-02-16T17:02:26.8631699Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2023-02-16T17:02:26.8710382Z ##[section]Finishing: Restore Nuget Packages

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 03:18:24