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

dotnet restore报错找不到指定版本包却提示已找到该版本

解决dotnet restore时NU1102矛盾错误

问题描述

执行dotnet restore时收到NU1102错误,提示找不到版本≥1.1.0的ApplicationLogic.Contract包,但同时显示GitLab源中存在该版本:

/code/modules-mobilebanking/Modules.MobileBanking.API/Modules.MobileBanking.API.csproj : error NU1102: Unable to find package ApplicationLogic.Contract with version (>= 1.1.0)
       /code/modules-mobilebanking/Modules.MobileBanking.API/Modules.MobileBanking.API.csproj : error NU1102:   - Found 2 version(s) in GitLab [ Nearest version: 1.1.0 ]
       /code/modules-mobilebanking/Modules.MobileBanking.API/Modules.MobileBanking.API.csproj : error NU1102:   - Found 0 version(s) in nuget.org

已确认GitLab源中确实存在1.0.0和1.1.0版本,且拥有该源的读写权限,其他十几个包均可正常从该源还原:

{
"@type": "Package",
"authors": "",
"id": "ApplicationLogic.Contract",
"title": "ApplicationLogic.Contract",
"summary": "",
"totalDownloads": 0,
"verified": true,
"version": "1.1.0",
"versions": [
{
"@id": "https://gtlb.company.com/api/v4/projects/25/packages/nuget/metadata/ApplicationLogic.Contract/1.1.0.json",
"version": "1.1.0",
"downloads": 0
},
{
"@id": "https://gtlb.company.com/api/v4/projects/25/packages/nuget/metadata/ApplicationLogic.Contract/1.0.0.json",
"version": "1.0.0",
"downloads": 0
}
],
"tags": ""
}

解决步骤

  • 清除NuGet本地缓存
    本地缓存损坏可能导致NuGet无法正确识别源中的包版本,执行以下命令清除缓存:

    dotnet nuget locals all --clear
    

    清除后重新执行dotnet restore。

  • 显式指定还原源顺序
    确保NuGet优先检查GitLab源,执行还原时显式指定源(将GitLab源放在前面):

    dotnet restore --source "https://gtlb.company.com/api/v4/projects/25/packages/nuget/index.json" --source https://api.nuget.org/v3/index.json
    
  • 检查项目与包的目标框架兼容性
    项目的TargetFramework可能与包支持的框架不匹配,导致即使存在版本也无法使用。执行以下命令查看包支持的框架:

    dotnet nuget show package ApplicationLogic.Contract --source "你的GitLab源名称" --framework netX.X
    

    替换netX.X为项目的TargetFramework(如net6.0),对比是否匹配。

  • 验证GitLab源配置权限
    检查NuGet.config中GitLab源的令牌是否具备read_api和read_repository权限,配置示例:

    <packageSources>
      <add key="GitLab" value="https://gtlb.company.com/api/v4/projects/25/packages/nuget/index.json" />
      <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    </packageSources>
    <packageSourceCredentials>
      <GitLab>
        <add key="Username" value="你的用户名" />
        <add key="ClearTextPassword" value="你的个人访问令牌" />
      </GitLab>
    </packageSourceCredentials>
    

    若令牌权限不足,重新生成具备对应权限的令牌并更新配置。

内容的提问来源于stack exchange,提问作者D. Reagan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 00:15:46