Linux(Docker)下Dotnet Build报MSB3202:项目文件未找到(Windows正常)
.NET Core解决方案在Docker容器中构建失败问题
背景
我正在构建一个包含两个项目的.NET Core解决方案,Windows本地执行dotnet build能正常完成,但在Debian GNU/Linux 11的Docker容器中构建整个解决方案时失败,不过进入单个项目目录执行构建却可以成功。
解决方案文件内容
Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.32930.78 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataAccess", "DataAccess\DataAccess.csproj", "{A2215C05-2906-47D8-A51E-986167EED172}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{5D3617CC-A0CC-437F-96CC-D64B6F23A668}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A2215C05-2906-47D8-A51E-986167EED172}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Debug|Any CPU.Build.0 = Debug|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Debug|x64.ActiveCfg = Debug|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Debug|x64.Build.0 = Debug|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Release|Any CPU.ActiveCfg = Release|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Release|Any CPU.Build.0 = Release|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Release|x64.ActiveCfg = Release|Any CPU {A2215C05-2906-47D8-A51E-986167EED172}.Release|x64.Build.0 = Release|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Debug|x64.ActiveCfg = Debug|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Debug|x64.Build.0 = Debug|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Release|Any CPU.Build.0 = Release|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Release|x64.ActiveCfg = Release|Any CPU {5D3617CC-A0CC-437F-96CC-D64B6F23A668}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5EECAB02-1A61-4FAD-9E00-5B1292E418E6} EndGlobalSection EndGlobal
Windows本地构建结果
在解决方案目录执行dotnet build,输出如下:
dotnet build MSBuild version 17.3.2+561848881 for .NET Determining projects to restore... All projects are up-to-date for restore. Common -> C:\git\Common\bin\Debug\netstandard2.1\Common.dll Common -> C:\git\Common\bin\Debug\netstandard2.0\Common.dll DataAccess -> C:\git\DataAccess\bin\Debug\netstandard2.0\DataAccess.dll Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:03.08
Docker容器中构建失败信息
容器系统信息
PS /> cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
构建报错输出
在容器的解决方案目录执行dotnet build,报错如下:
PS /App> pwd Path ---- /App PS /App> dotnet build MSBuild version 17.3.2+561848881 for .NET /usr/share/dotnet/sdk/6.0.405/NuGet.targets(369,5): error MSB3202: The project file "/App/Common/Common.csproj" was not found. [/App/My.sln] Build FAILED. /usr/share/dotnet/sdk/6.0.405/NuGet.targets(369,5): error MSB3202: The project file "/App/Common/Common.csproj" was not found. [/App/My.sln] 0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.24
补充信息
编辑1:Dockerfile内容
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env WORKDIR /App COPY . ./ RUN dotnet nuget add source 'https://pkgs.dev.azure.com/myorg/_packaging/2bba9c97-9acb-40b5-aa6c-17e17617e3aa/nuget/v3/index.json' -u 'tst' -p 'XXXXXXXXX' --store-password-in-clear-text RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \ && dpkg -i packages-microsoft-prod.deb \ && rm packages-microsoft-prod.deb \ && apt-get update && apt-get install -y powershell
编辑2:单个项目构建成功结果
进入容器内的Common项目目录执行dotnet build,输出如下:
PS /App/Common> pwd Path ---- /App/Common PS /App/Common> dotnet build MSBuild version 17.3.2+561848881 for .NET Determining projects to restore... All projects are up-to-date for restore. Common -> /App/common/bin/Debug/netstandard2.1/Common.dll Common -> /App/common/bin/Debug/netstandard2.0/Common.dll Build succeeded. 0 Warning(s) 0 Error(s) Time Elapsed 00:00:00.67
编辑3:确认文件存在
容器内已确认项目文件存在:
PS /> pwd Path ---- / PS /> ls /App/common/Common.csproj /App/common/Common.csproj
内容的提问来源于stack exchange,提问作者Alexey Auslender
相关产品推荐
相关产品推荐

