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

自托管Windows Bitbucket Runner上NuGet路径缺失错误求助

解决Bitbucket自托管Windows Runner的NuGet还原路径错误

问题背景

我正在为.NET Framework项目搭建基于自托管Windows Runner的Bitbucket流水线,配置的bitbucket-pipeline.yml内容如下:

pipelines:
  default:
    - step:
        name: Build and test
        runs-on:
          - "windows"
        script:
          - nuget.exe restore .\MyProject.sln -source "https://api.nuget.org/v3/index.json;http://nuget.mycompany.com/nuget"
          - msbuild .\MyProject.sln 

执行流水线时出现NuGet错误,具体报错信息:

...
Adding package 'System.ValueTuple.4.5.0' to folder 'C:\Windows\system32\atlassian-bitbucket-pipelines-runner\temp\200c6e7a-b2bb-52a1-93a4-59b520d83266\1682613154669\build\packages'
Restoring NuGet package WebGrease.1.6.0.
Adding package 'WebGrease.1.6.0' to folder 'C:\Windows\system32\atlassian-bitbucket-pipelines-runner\temp\200c6e7a-b2bb-52a1-93a4-59b520d83266\1682613154669\build\packages'


Errors in packages.config projects
    Could not find a part of the path 'C:\Windows\system32\atlassian-bitbucket-pipelines-runner\temp\200c6e7a-b2bb-52a1-93a4-59b520d83266\1682613154669\build\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.11.0\build\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.targets'.
    Could not find a part of the path 'C:\Windows\system32\atlassian-bitbucket-pipelines-runner\temp\200c6e7a-b2bb-52a1-93a4-59b520d83266\1682613154669\build\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.11.0\build\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.targets'.

NuGet Config files used:
    C:\Windows\system32\atlassian-bitbucket-pipelines-runner\temp\200c6e7a-b2bb-52a1-93a4-59b520d83266\1682613154669\build\NuGet.Config
    C:\Users\myPc\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    C:\Users\myPc\.nuget\packages\
    https://api.nuget.org/v3/index.json
    http://nuget.mycompany.com/nuget

Installed:
    33 package(s) to packages.config projects

解决方案

  • 指定本地Packages目录:在NuGet还原命令中添加-PackagesDirectory参数,将包下载到项目目录下的packages文件夹,避免系统目录权限或长路径问题。修改后的命令:
    nuget.exe restore .\MyProject.sln -source "https://api.nuget.org/v3/index.json;http://nuget.mycompany.com/nuget" -PackagesDirectory .\packages
    
  • 调整Runner工作目录权限:检查Bitbucket Runner服务运行账号对C:\Windows\system32\atlassian-bitbucket-pipelines-runner目录的读写权限,或者直接将Runner的工作目录迁移到非系统盘(如D盘),规避系统目录的权限限制。
  • 清理后重新还原:在流水线脚本中先清理旧的packages目录,再执行还原操作,避免缓存文件冲突:
    - rmdir /s /q .\packages
    - nuget.exe restore .\MyProject.sln -source "https://api.nuget.org/v3/index.json;http://nuget.mycompany.com/nuget" -PackagesDirectory .\packages
    
  • 更新NuGet版本:使用5.x及以上版本的NuGet.exe,旧版本对长路径、特殊目录的处理存在bug。可在流水线脚本中先下载最新版NuGet再执行还原:
    - Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile nuget.exe
    - .\nuget.exe restore .\MyProject.sln -source "https://api.nuget.org/v3/index.json;http://nuget.mycompany.com/nuget" -PackagesDirectory .\packages
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 16:02:50