Posted by Mete Atamel, Developer Advocate
Google Cloud Shell, my favorite development tool for Google Cloud Platform, just got more awesome with two new features.
First, we recently integrated Eclipse Orion, an online code editor, with Cloud Shell. If you’re not a Vim or Emacs fan, Orion is a welcome addition to Cloud Shell. It enables you to edit code right inside the browser with basic syntax highlighting and minimal effort.
Second, we added .NET Core command line interface tools to Cloud Shell. This is a new cross-platform toolchain for developing .NET Core applications and it can be used to create, run and publish .NET Core apps from the command line.
With these two new additions, you can easily create an ASP.NET Core web app in Cloud Shell, edit it using Orion and run it on a Linux instance (yes, ASP.NET Core apps run on Linux!) right inside your browser. Let’s take a look at the steps involved.
Create an ASP.NET web app in Cloud Shell
From Google Cloud Console, click on the Cloud Shell icon on the top right section of the toolbar to activate Cloud Shell:
And, create a folder for our HelloWorld app:
$ mkdir HelloWorldAspNetCore
$ cd HelloWorldAspNetCore
Then, create a skeleton ASP.NET Core web app using the dotnet command:
$ dotnet new -t web
Created new C# project in /home/atameldev/HelloWorldAspNetCore.
Use Orion to change the default port
By default, ASP.NET Core web apps run on port 5000. Let’s change that to a more conventional port for web apps, port 8080.
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup()
.UseUrls(“http://*:8080″)
.Build();
host.Run();
}
Open Orion by clicking Files and then Launch Code Editor at the top of Cloud Shell. Once the code editor is open, find Program.cs in the folder:
Add the UseUrls line to bind to port 8080:
Run the ASP.NET web app
We’re almost ready to run our app but we need to restore dependencies first. This will download all the NuGet dependencies for our app:
$ dotnet restore
…
log : Restore completed in 16298ms.
Finally, run our app:
$ dotnet run
…
Now listening on: http://*:8080
Application started. Press Ctrl+C to shut down.
At this point, our app is running on Linux! Don’t believe it? You can convince yourself by visiting the web preview and Preview on port 8080:
You’ll see the default ASP.NET Core webpage in a new tab.
Next steps
There! You’ve just created and launched an ASP.NET Core app from inside Cloud Shell, without once leaving your browser. But that’s not all you can do. You can take your newly created ASP.NET Core app, containerize it using Docker and deploy it to Google App Engine or you can let Kubernetes manage it all for you in Google Container Engine. It’s easy to see why Cloud Shell is my favorite GCP development tool.
Quelle: Google Cloud Platform
Published by