Install and use Cloud Tools for Visual Studio

1. Overview

Visual Studio is the go-to IDE for Windows and .NET developers. Cloud Tools for Visual Studio is a plugin to build and test Windows and .NET applications locally and deploy them to Google Cloud Platform directly from Visual Studio.

Google Cloud Explorer lets you easily browse Google Cloud projects and resources across all of your accounts in Visual Studio.

In this codelab, you will learn how to install and use Cloud Tools for Visual Studio and how to interact with Google Cloud resources from Visual Studio directly.

What you'll learn

  • How to install Cloud Tools for Visual Studio.
  • How to authenticate to Google Cloud Platform.
  • How to use Google Cloud Explorer to manage resources.
  • How to create and manage Google Compute Engine instances.
  • How to create and deploy ASP.NET apps
  • How to browse Google Cloud Storage.

What you'll need

How will you use this tutorial?

Read it through only Read it and complete the exercises

How would rate your experience with Google Cloud Platform?

Novice Intermediate Proficient

2. Setup and Requirements

For this codelab, you need a Google Cloud Platform project to interact with Visual Studio. If you have an existing project, you can either use that or you can create a new project using the following steps.

Self-paced environment setup

If you don't already have a Google Account (Gmail or G Suite), you must create one. Sign-in to Google Cloud Console ( console.cloud.google.com) and create a new project:

aa2b71cbc7c28c59.png

60b154eb0fd9569a.png

Remember the project ID, a unique name across all Google Cloud Platform projects. It will be referred to later in this codelab as PROJECT_ID.

Next, you need to enable billing in Google Cloud Console in order to use Google Cloud Platform resources like Google Cloud Datastore and Cloud Storage.

New users of Google Cloud Platform are eligible for a $300 free trial. Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see the "cleanup" section at the end of this document).

3. Installation

Cloud Tools for Visual Studio can be installed directly within Visual Studio from Visual Studio Gallery. Start Visual Studio, go to Tools menu and select Extensions and Updates. This opens a new window. On the left hand side, select Online and then Visual Studio Gallery. On the right hand side, you should see Search Visual Studio Gallery text input. Search for Google Cloud. This should list a number of results but you should see Google Cloud Tools for Visual Studio.

793794e10f2e6f68.png

Click on Download. This will download the plugin and then you can click on Install to install it. Once installation is complete, you need to restart Visual Studio.

To make sure everything installed correctly, you should see a new Google Cloud Tools menu item under the Tools menu of Visual Studio.

4. Authentication

Before you can use Cloud Tools for Visual Studio, you need to authenticate to Google Cloud Platform. Go to Tools > Google Cloud Tools > Manage Accounts > Add Account.

This should open up a new browser window where you can login with your Google account. If a default browser is not set, sometimes you can get stuck with "How do you want to open this website?" dialog. In that case, make sure you set Chrome as the default browser and try again.

Then, you should grant Cloud Tools for Visual Studio access your Google Cloud Platform project. Once finished, you should see Visual Studio is now authorized to access your account message.

You can close the browser and go back to Visual Studio. Take a look under Google Cloud Tools > Manage Accounts again. You should see your account listed.

5. Google Cloud Explorer

Once authenticated, you're ready to use Google Cloud Explorer to manage resources. In Visual Studio, go to Tools > Google Cloud Tools > Show Google Cloud Explorer.

This opens up a new window. At the top, choose your Google Cloud Platform project. In the middle, you can see Compute Engine, Cloud Storage and Cloud SQL resources.

801c1722b560f407.png

In the next section, you will learn how to create and manage Compute Engine instances from Visual Studio.

6. Create and Manage Google Compute Engine instances

Create an instance

In this section, you will deploy a Windows machine with ASP.NET framework installed to Compute Engine. To do that, right click on Google Compute Engine and select New ASP.NET instance.

ef78cea8bca7ff1e.png

This opens up a new browser window with Cloud Launcher. Follow the prompts to deploy a Windows instance with ASP.NET framework. It will take a few minutes for the deployment to finish. Once it's completed, you should see the new instance in the list of Compute Engine instances both in Visual Studio and Google Cloud console.

Create a Windows username and password

To connect using remote desktop to the new virtual machine or save the publishing settings file (to use during deployments), you need to create a Windows username and password. Right-click on the newly created Compute Engine instance (which will start with "aspnet") and choose Manage Windows credentials.

573d93972b3d6fff.png

On the next screen, you can create a Windows user and a password (or let Visual Studio plugin generate one for you). If you see a "you need to have the beta component of Google Cloud SDK installed" error, follow the instructions to install beta components and then proceed with creating the user. Once the user is created, you should see it under list of users.

To test that you can RDP into the instance with the new Windows user, you can right-click on the Compute Engine instance again and select Open Remote Desktop session and select the Windows user you just created from the drop-down menu. Click Open and then Connect. If you get a certificate warning, ignore it and proceed by selecting Yes. After a few seconds, you should see a Remote Desktop session opened to your Windows instance running on Compute Engine.

6792760b1829ebd1.png

Save publishing settings

There are other actions you can take on a Compute Engine instance from Visual Studio such as setting up firewall rules or stopping the instance. To see the full list, right-click on the instance.

You can go through them yourself but let's make sure to save publish settings file. Select Save publishing settings, select the Windows username and then download the file. You will use this file to deploy a simple ASP.NET app to Google Cloud Platform in the section.

7. Create and Deploy ASP.NET apps

Create ASP.NET MVC app from Google Cloud Platform project template

Cloud Tools Visual Studio comes with some Google Cloud Platform project templates. In this section, you will create a simple ASP.NET MVC app using one of those templates and deploy it to Google Cloud Platform using the publishing settings file you saved earlier.

To get started, in Visual Studio, go to New > Project > Visual C# > Google Cloud Platform. There are two Google Cloud Platform templates, one for MVC and one for Web API. Choose the Google ASP.NET 4 MVC template. Adjust the project name, solution name, and location as you prefer and click OK. This will create a new solution and a project for the ASP.NET app.

Run the app locally

To test the app locally, go to Debug > Start Debugging. This will first download NuGet dependencies and then build the app. In a few seconds, a browser window should pop-up with the MVC app running locally.

6f264456e8038700.png

Once you have verified that the app is running as expected, stop the app (Shift + F5).

Deploy the app to Google Cloud

Now, you're ready to deploy the app to Google Cloud Platform. Right-click on the project and click Publish.

8d230a4bbcc6aa44.png

This opens up the publish dialog. In the publish dialog, select Import as the publish target and point to the publishing settings file you downloaded earlier.

You should see a connection dialog with server, site name etc. pre-filled. Make sure your connection is good by clicking on Validate Connection. You should see a green arrow shortly afterwards.

396613835acc065f.png

Click Next and under File Publish Options, make sure Remove additional files at destination is checked.

bb25fd89ffcca1e.png

Click Publish. This will build and publish the app to Google Cloud. In the end, you should see Publish Succeeded message in output window.

55a920a8ae2c44e.png

At this point, you should be able to visit the external IP of the Compute Engine instance and see the default MVC app. The easiest way is to go to Tools > Google Cloud Tools > Show Google Cloud Explorer, right-click on the Compute Engine instance and select Open Website.

b80e32136c037a0.png

8. Browse Google Cloud Storage

In this part of the codelab, you will create a Cloud Storage bucket, upload a random file to the bucket and then use Google Cloud Explorer to browse to that bucket.

To create a bucket, go to Google Cloud Console, select Storage under the list of products.

25f93c20933f0b87.png

Select Create Bucket, give it a unique name and click Create. Once the bucket is created, you can upload files to it and see them under storage browser.

9912d408cdb51f31.png

Now, go back to Visual Studio and open up Google Cloud Explorer. At the top-left, hit Refresh button. Under Google Cloud Storage, you should see your new bucket. You can right-click on the bucket and select Open on Cloud Platform Console to browse the bucket.

882ff1d836529d2d.png

9. Congratulations!

In this codelab, you learned how to manage Compute Engine instances and Cloud Storage buckets from Visual Studio but there's more! You can also manage Cloud SQL resources from Visual Studio but that's left as an exercise for the reader. Check out the list of next steps below to learn more.

What we've covered

  • How to install Cloud Tools for Visual Studio.
  • How to authenticate to Google Cloud Platform.
  • How to use Google Cloud Explorer to manage resources.
  • How to create and manage Google Compute Engine instances.
  • How to create and deploy ASP.NET apps
  • How to browse Google Cloud Storage.

Next Steps