need a little help resolving this issue I’m facing when building my ASP.NET project that references a local class library inside a docker container.
I’m using:
- ASP.NET 6.0
- Docker version 20.10.21, build baeda1f
- dotnet sdk 6.0
When I try to run
docker build .
I get the following error:
=> 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
The dockerfile
I’m using
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"]
The .csproj
file
<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>....PackageNamePackageNamebinDebugnetstandard2.1PackageName.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Any thoughts on me getting the dockerfile
to fetch the package .dll
on build? or is it the wrong way to go about getting what I want?
I am open to hosting the package on nuget but for the time being this dockerfile
is for dev purposes only.
Keep in mind that the package is at the right location locally, as building the project using:
dotnet build ProjectName.csproj
works fine
P.S. I replaced the package name with "PackageName" and the project name with "ProjectName".
I tried building the dockerfile for ASP.NET 6.0 and I expected it to pass, but I got an Error instead.
2
Answers
So I solved this almost immediately, I made the class library build to the location with my asp.net project, cleared the docker cache, and built again.
Id project located on your computer, You need to copy xxx.dll after define
SWORKDIR /src
COPY ["Xxx.csproj", "."]
COPY ["output/Debug/net6.0/xxx.dll", "."]
Otherwise you have to create nuget package the dll then you install from nuget