Ankit Sharma
Ankit Sharma

Reputation: 55

Run latest ASP.NET Core version on Google App Engine

I've been working on a .net core 2.0 web app recently and thought of using Google's App Engine on google cloud to host it, but as per the tutorial, google cloud uses .net core 1.0 which doesn't support my project. Is there any way i can run app made using the newer sdk on the cloud?

Upvotes: 2

Views: 1091

Answers (3)

olfek
olfek

Reputation: 3520

Part 1

Make sure you have the following two files

  • app.yaml
  • Dockerfile

with the contents shown below in the root of your project.

app.yaml

env: flex
runtime: custom

Dockerfile

FROM [DOCKER_IMAGE_URL]
COPY . /app
WORKDIR /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://*:8080
ENTRYPOINT ["dotnet", "[NAME_OF_PROJECT].dll"]

Remember to replace [NAME_OF_PROJECT] with the name of your project and [DOCKER_IMAGE_URL] with one of the URLs from here:

https://hub.docker.com/_/microsoft-dotnet-core-aspnet/

For example: mcr.microsoft.com/dotnet/core/aspnet:3.0 for ASP.NET Core 3.0

Part 2

For the files we created in part 1 to be put into use, they need to be copied to the output/build directory when we run the build command.

This can be done by adding the following

<ItemGroup>
  <None Include="app.yaml"   CopyToOutputDirectory="PreserveNewest" />
  <None Include="Dockerfile" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

to your .csproj file.

Now when we run the build command, they will be copied to ./bin/Release/netcoreapp[VERSION]/publish for the release build and ./bin/Debug/netcoreapp[VERSION] for the debug build.

where [VERSION] is the ASP.NET Core version you are using.

Part 3

From here, deploy using the Google Cloud SDK as usual.


Thanks to:

  1. https://www.youtube.com/watch?v=tZRam__Bx6o
  2. https://cloud.google.com/appengine/docs/flexible/dotnet/runtime
  3. https://docs.docker.com/engine/examples/dotnetcore/
  4. https://cloud.google.com/blog/products/gcp/4-ways-you-can-deploy-an-aspnet-core-app-to-gcp

Upvotes: 3

Ivan Naranjo
Ivan Naranjo

Reputation: 31

Sadly the tutorial is out of date. We have runtime images for .NET Core 1.0, 1.1 and 2.0 now a days. We're going through our documentation and fixing it, but it takes a while.

From the instructions in this updated quickstart you will need to have a minimal app.yaml, something like:

env: flex
runtime: aspnetcore

Then, from the root of your project you run:

dotnet restore
dotnet publish -c Release

Copy the app.yaml to the output of the publish process, typically bin\Release\netcore2.0\publish and then deploy your app with:

gcloud beta app deploy bin\Release\netcore2.0\publish\app.yaml

This command will detect what version of .NET Core you are using and build the appropriate Docker image for you.

Note that the .NET Core support in App Engine Flexible is still in beta, we're working really hard to go to GA soon.

Upvotes: 3

Tseng
Tseng

Reputation: 64180

You can deploy your application as self-contained application, then you can run it w/o a runtime installed.

It's well describe in the ASP.NET Core documentation Self-contained deployment without third-party dependencies

It boils down to adding <RuntimeIdentifier> or <RuntimeIdentifiers> Elements to your csproj file.

<PropertyGroup>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
</PropertyGroup>

and doing a dotnet restore, followed by a dotnet build.

Finally you can publish it to one of the platforms you defined above:

dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r osx.10.11-x64

The self-deployment will download all files necessary from nuget, this includes the .NET Core runtime and put it into the output folder.

Upvotes: 0

Related Questions