我需要一些帮助来解决我在构建ASP.NET项目时遇到的这个问题,该项目引用Docker容器中的本地类库。
我正在使用:
- ASP.NET 6.0语言
- Docker版本20.10.21,构建版本baeda1f
- 互联网软件开发工具包6.0
当我尝试运行docker build .
时
出现以下错误:
=> ERROR [build 7/7] RUN dotnet build "ProjectName.csproj" -c Debug -o /app/build 1.9s
------
> [build 7/7] RUN dotnet build "ProjectName.csproj" -c Debug -o /app/build:
#15 0.434 MSBuild version 17.3.2+561848881 for .NET
#15 0.655 Determining projects to restore...
#15 0.885 All projects are up-to-date for restore.
#15 1.042 /usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk. If this reference is required
by your code, you may get compilation errors. [/src/ProjectName/ProjectName.csproj]
#15 1.847 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProjectName/ProjectName.csproj]
#15 1.852
#15 1.852 Build FAILED.
#15 1.852
#15 1.852 /usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk. If this reference is required
by your code, you may get compilation errors. [/src/ProjectName/ProjectName.csproj]
#15 1.852 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProjectName/ProjectName.csproj]
#15 1.852 1 Warning(s)
#15 1.852 1 Error(s)
#15 1.852
#15 1.852 Time Elapsed 00:00:01.38
------
executor failed running [/bin/sh -c dotnet build "ProjectName.csproj" -c Debug -o /app/build]: exit code: 1
我使用的dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ProjectName.csproj", "ProjectName/"]
RUN dotnet restore "ProjectName/ProjectName.csproj"
COPY .. .
WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Publish -o /app/build
FROM build AS debug
RUN dotnet publish "ProjectName.csproj" -c Publish -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectName.dll"]
.csproj
文件
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
....
</ItemGroup>
<ItemGroup>
<Reference Include="PackageName">
<HintPath>..\..\PackageName\PackageName\bin\Debug\netstandard2.1\PackageName.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
有没有关于我让dockerfile
在构建时获取.dll
包的想法?或者这是一个错误的方法来获取我想要的东西?
我愿意在nuget上托管这个包,但目前这个dockerfile
只用于开发目的。
请记住,包在本地位于正确的位置,因为生成项目时使用:dotnet build ProjectName.csproj
工作正常
P. S. I将包名替换为"PackageName",将项目名替换为"ProjectName"。
我试着为ASP.NET6.0构建dockerfile,我希望它能通过,但是我得到了一个错误。
2条答案
按热度按时间wnavrhmk1#
所以我几乎立刻就解决了这个问题,我用我的www.example.com项目将类库构建到这个位置asp.net,清除Docker缓存,然后再次构建。
trnvg8h32#
ID项目位于您的计算机上,您需要在定义后复制xxx.dll
软件目录/源代码副本[“Xxx.csproj”,“."]副本[“输出/调试/net6.0/xxx. dll”,“."]
否则,您必须创建nuget包的dll,然后从nuget安装