'Custom runtime dockerfile for asp.net core 5 with Google cloud error CS1003: Syntax error,
I am trying to publish the Asp.net core 5 application to the google cloud using the visual studio plugin.
app.yaml
runtime: custom
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Docker file
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 8080
ENV ASPNETCORE_URLS=http://*:8080
ENTRYPOINT ["dotnet", "Falcon-Identity.dll"]
When I publish using publish to google cloud from context menu I am getting the below exception
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,23): error CS1003: Syntax error, '(' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,23): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,30): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,30): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,31): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,37): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,37): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(1,41): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(2,9): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(2,9): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(2,10): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(3,3): error CS1024: Preprocessor directive expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(4,6): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(4,8): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(4,16): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(4,16): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(4,17): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(5,12): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(6,3): error CS1024: Preprocessor directive expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(7,6): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(7,10): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,12): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,20): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,20): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,21): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,31): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,32): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,34): error CS1001: Identifier expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(8,34): error CS1003: Syntax error, ',' expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(9,3): error CS1024: Preprocessor directive expected [C:\Projects\falcon-identity\Falcon-Identity\Falcon-Identity.csproj]
C:\Projects\falcon-identity\Falcon-Identity\Dockerfile(10,9): error CS1003: Syntax error, ',' e
Solution 1:[1]
I encountered an identical problem with same exceptions. It was caused by setting the build action on the docker file incorrectly (properties tab - incorrectly set the build action of the file to "C# compiler" instead of "None").
Solution 2:[2]
I'm able to deploy an ASP.NET 5.0 app successfully to App Engine flex (and then Cloud Run).
I'm less familiar with .NET and so I used a simpler configuration but, I think you should be able to apply what I've done to your case too.
Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:5.0
WORKDIR /app
COPY ./app/*.csproj .
RUN dotnet restore
COPY ./app/ .
EXPOSE 8080
ENTRYPOINT ["dotnet", "run","--urls=http://+:8080"]
And:
BILLING=...
PROJECT=...
REGION=...
gcloud projects create ${PROJECT}
gcloud beta billing projects link ${PROJECT} \
--billing-account=${BILLING}
gcloud app create \
--region=${REGION} \
--project=${PROJECT}
mkdir ${PWD}/app
# Create 'empty' ASP.NET (web)app
docker run \
--interactive --tty --rm \
--volume=${PWD}/app:/app \
mcr.microsoft.com/dotnet/sdk:5.0 \
dotnet new webapp -o app
# Change generated files to `$whoami`
# Or `$(id -u):$(id -g)`
chown -R $(whoami):$(whoami) ./app
docker build \
--tag=68103677:v1 \
--file=./Dockerfile \
.
docker run \
--interactive --tty --rm \
--publish=8080:8080 \
68103677:latest
# Prove it
curl localhost:8080
# Deploy
gcloud app deploy ./app.yaml \
--project=${PROJECT} \
--quiet
# Test
gcloud app browse \
--project=${PROJECT}
Just for giggles, we can deploy the container image created by the App Engine deployment and deploy the container to Cloud Run:
gcloud services enable run.googleapis.com \
--project=${PROJECT}
# Grab the App Engine image
IMAGE=$(\
gcloud container images list \
--repository=us.gcr.io/${PROJECT}/appengine \
--limit=1 \
--format="value(name)")
# Deploy it to Cloud Run
# For testing, deploy without authentication
# We need to replicate `ENTRYPOINT` with `--command` and `--args`
NAME="aspnet"
gcloud run deploy ${NAME} \
--image=${IMAGE} \
--command="dotnet" \
--args="run","--urls=http://+:8080" \
--max-instances=1 \
--region=${REGION} \
--project=${PROJECT} \
--allow-unauthenticated
# Grab its endpoint
ENDPOINT=$(\
gcloud run services describe ${NAME} \
--project=${PROJECT} \
--platform=managed \
--region=${REGION} \
--format="value(status.address.url)") && \
echo ${ENDPOINT}
# Browse or...
curl ${ENDPOINT}
# Delete it when done
gcloud run services delete ${NAME} \
--region=${REGION} \
--project=${PROJECT} \
--quiet
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Josef Fuksa |
| Solution 2 |
