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

William Douglas 0 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.
4,625 questions
{count} votes