diff --git a/pkg/project/runtime/csharp.dockerfile b/pkg/project/runtime/csharp.dockerfile index 2d5ee86e0..9796bf742 100644 --- a/pkg/project/runtime/csharp.dockerfile +++ b/pkg/project/runtime/csharp.dockerfile @@ -1,4 +1,7 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# https://github.com/dotnet/runtime/issues/94909 +ENV DOTNET_EnableWriteXorExecute=0 ARG HANDLER @@ -8,11 +11,13 @@ WORKDIR /app COPY . ./ # Build and publish a release -RUN dotnet publish -c Release -o out --self-contained -p:PublishSingleFile=true -p:PublishTrimmed=true +RUN dotnet publish -c Release -o out --self-contained -p:PublishSingleFile=true # Build runtime image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0 +FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 + +ARG HANDLER -COPY --from=build /app/out/hello /usr/bin/handler +COPY --from=build /app/out/${HANDLER} /usr/bin/handler ENTRYPOINT ["handler"] \ No newline at end of file diff --git a/pkg/project/runtime/runtime.go b/pkg/project/runtime/runtime.go index eedea3579..a917f7ddc 100644 --- a/pkg/project/runtime/runtime.go +++ b/pkg/project/runtime/runtime.go @@ -73,11 +73,14 @@ var csharpDockerfile string var csharpIgnores = append([]string{"obj/", "bin/"}, commonIgnore...) func csharpBuildContext(entrypointFilePath string, additionalIgnores []string) (*RuntimeBuildContext, error) { + // Convert the service name to the name of the binary produced. i.e. services/hello.csproj -> hello + handler := strings.ReplaceAll(filepath.Base(entrypointFilePath), ".csproj", "") + return &RuntimeBuildContext{ DockerfileContents: csharpDockerfile, BaseDirectory: ".", // use the nitric project directory BuildArguments: map[string]string{ - "HANDLER": filepath.ToSlash(entrypointFilePath), + "HANDLER": handler, }, IgnoreFileContents: strings.Join(append(additionalIgnores, csharpIgnores...), "\n"), }, nil @@ -182,7 +185,7 @@ func NewBuildContext(entrypointFilePath string, dockerfilePath string, buildArgs ext := filepath.Ext(entrypointFilePath) switch ext { - case ".cs": + case ".csproj": return csharpBuildContext(entrypointFilePath, additionalIgnores) case ".go": return golangBuildContext(entrypointFilePath, additionalIgnores)