Bitbucket Pipeline中dotnet restore无法找到csproj文件求助
Bitbucket Pipeline执行dotnet restore失败:找不到csproj文件排查
问题说明
Bitbucket Pipeline执行dotnet restore时失败,提示无法找到项目结构中的csproj文件。本地使用.NET 8可正常还原和构建,Bitbucket项目结构与本地一致,已知存在命名大小写不一致问题,以下是相关配置、报错信息及项目结构,附排查修复方案。
现有YAML配置
image: mcr.microsoft.com/dotnet/sdk:8.0 pipelines: branches: main: - step: name: Restore and Build script: - dotnet restore ./src/*.sln - step: name: Build and store binaries script: - dotnet build -c Release ./src/*.sln artifacts: paths: - ./BuildingBlocks/bin/** - ./Services/**/**/bin/**
报错信息
dotnet restore ./src/*.sln /usr/share/dotnet/sdk/8.0.404/NuGet.targets(465,5): error MSB3202: The project file "/opt/atlassian/pipelines/agent/build/src/Services/Basket/Basket.API/basket.API.csproj" was not found. [/opt/atlassian/pipelines/agent/build/src/eshopmicroservices.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(465,5): error MSB3202: The project file "/opt/atlassian/pipelines/agent/build/src/Services/Catalog/Catalog.Api/Catalog.csproj" was not found. [/opt/atlassian/pipelines/agent/build/src/eshopmicroservices.sln] /usr/share/dotnet/sdk/8.0.404/NuGet.targets(465,5): error MSB3202: The project file "/opt/atlassian/pipelines/agent/build/src/BuildingBlocks/BuildingBlocks.csproj" was not found. [/opt/atlassian/pipelines/agent/build/src/eshopmicroservices.sln]
本地项目结构
-Eshop - eshopmicroservices.sln -src -BuildingBlocks - BuildingBlocks.csproj -Services - Catalog - Catalog.Api - Catalog.csproj - Basket - Basket.API - Basket.Api.csproj
排查与修复方案
1. 修正解决方案文件路径
从项目结构可见,eshopmicroservices.sln与src目录同级,而非在src文件夹内。现有Pipeline命令错误地指向./src/*.sln,导致无法正确定位sln文件,进而引发后续路径错误。
修改Pipeline中的命令:
# 原restore命令 dotnet restore ./src/*.sln # 修正后 dotnet restore ./eshopmicroservices.sln # 原build命令 dotnet build -c Release ./src/*.sln # 修正后 dotnet build -c Release ./eshopmicroservices.sln
同时修正artifacts路径(原路径未包含src前缀,与实际结构不符):
artifacts: paths: - ./src/BuildingBlocks/bin/** - ./src/Services/**/**/bin/**
2. 统一文件路径大小写
Bitbucket Pipeline基于Linux环境运行,对文件路径大小写敏感;而本地Windows/macOS默认不区分大小写,因此本地正常但Pipeline报错。对比报错与实际结构:
- 报错中寻找
basket.API.csproj,实际文件为Basket.Api.csproj - 需确保解决方案文件(.sln)中记录的项目路径与实际文件系统完全一致:
- 打开
eshopmicroservices.sln,检查每个<Project>节点的Include属性 - 将错误的路径(如
basket.API.csproj)修正为实际的Basket.Api.csproj,确保大小写完全匹配
- 打开
修正后的完整YAML示例
image: mcr.microsoft.com/dotnet/sdk:8.0 pipelines: branches: main: - step: name: Restore and Build script: - dotnet restore ./eshopmicroservices.sln - step: name: Build and store binaries script: - dotnet build -c Release ./eshopmicroservices.sln artifacts: paths: - ./src/BuildingBlocks/bin/** - ./src/Services/**/**/bin/**
内容的提问来源于stack exchange,提问作者CMorgan
相关产品推荐
相关产品推荐

