Error building Dockerfile "Program does not contain a static 'Main' method suitable for an entry point"

William Douglas 5 Reputation points
2024-06-23T12:26:33.19+00:00

I have a dotnet-isolated 8 project that builds from the command line just fine.

When I run the same command within the Dockerfile, it's giving error :

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point.

Contents of Dockerfile:


FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release

COPY ["src/Usi.UChat.DocumentSync/Usi.UChat.DocumentSync.csproj", "src/Usi.UChat.DocumentSync/"]
COPY ["src/Usi.ChatGpt.Core/Usi.ChatGpt.Core.csproj", "src/Usi.ChatGpt.Core/"]
COPY ["Directory.Packages.props", "src"]
COPY ["Directory.Build.props", "src"]
COPY ["nuget.config", "src"]

WORKDIR /src

ARG NUGET_PASSWORD
RUN sed -i "s|</configuration>|<packageSourceCredentials><USIShared><add key=\"Username\" value=\"PAT\"/><add key=\"ClearTextPassword\" value=\"$NUGET_PASSWORD\"/></USIShared></packageSourceCredentials></configuration>|" nuget.config

RUN dotnet restore "./Usi.UChat.DocumentSync/Usi.UChat.DocumentSync.csproj" --ignore-failed-sources --configfile ./nuget.config

RUN dotnet build "./Usi.UChat.DocumentSync/Usi.UChat.DocumentSync.csproj" --no-restore   # <- FAILS HERE

RUN ls -l -R

FROM build AS publish
RUN dotnet publish "./Usi.UChat.DocumentSync/Usi.UChat.DocumentSync.csproj" -c $BUILD_CONFIGURATION -o /home/site/wwwroot --no-restore --no-build

FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 as base
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=publish ["/home/site/wwwroot", "/home/site/wwwroot"]

We have to split the restore into separate task because we utilize a private nuGet feed for some of our packages.

This is the csproj file:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net8.0</TargetFramework>
		<AzureFunctionsVersion>v4</AzureFunctionsVersion>
		<OutputType>Exe</OutputType>
		<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
	</PropertyGroup>
	<ItemGroup>
		<FrameworkReference Include="Microsoft.AspNetCore.App" />
		<PackageReference Include="Azure.Storage.Blobs" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Abstractions" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" />
		<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" />
		<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" />
		<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" />
		<PackageReference Include="Microsoft.Extensions.Hosting" />
		<PackageReference Include="Microsoft.Identity.Client" />
		<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" />
		<PackageReference Include="PnP.Core.Auth" />
		<PackageReference Include="PnP.Framework" />
	</ItemGroup>
	<ItemGroup>
		<ProjectReference Include="..\Usi.ChatGpt.Core\Usi.ChatGpt.Core.csproj" />
	</ItemGroup>
	<ItemGroup>
		<None Update="appsettings.json">
			<CopyToOutputDirectory>Always</CopyToOutputDirectory>
		</None>
		<None Update="host.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
		</None>
		<None Update="local.settings.json">
			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
			<CopyToPublishDirectory>Never</CopyToPublishDirectory>
		</None>
	</ItemGroup>
	<ItemGroup>
		<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
	</ItemGroup>
</Project>

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,124 questions
{count} vote

2 answers

Sort by: Most helpful
  1. António Mourão 0 Reputation points
    2024-09-29T14:23:24.2433333+00:00

    Same problem here.

    Not using centralised package management.

    0 comments No comments

  2. António Mourão 0 Reputation points
    2024-09-29T14:42:58.07+00:00

    The solution for my problem was to copy all the source to docker

    added the following command before the "dotnet restore" command:

    COPY /source/ .

    This command copies all the project source code into docker image, after this the project compiled successfully.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.