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.
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.
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:
Remember the project ID, a unique name across all Google Cloud Platform projects. It will be referred to later in this codelab as
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).
Cloud Tools for Visual Studio can be installed directly within Visual Studio from Visual Studio Gallery. In 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.
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.
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 opens up a new browser window where you can login with your Google account. 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.
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.
In the next section, you will learn how to create and manage Compute Engine instances from Visual Studio.
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.
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.
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 and choose Manage Windows credentials.
On the next screen, you can create a Windows user and a password (or let Visual Studio plugin generate one for you). Once the user is created, you should see it under list of users.
Now, 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.
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.
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.
To test the app locally, press F5. 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.
Once you have verified that the app is running as expected, stop the app (Shift + F5).
Now, you're ready to deploy the app to Google Cloud Platform. Right-click on the project and click Publish.
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.
Click Next and under File Publish Options, make sure Remove additional files at destination is checked.
Click Publish. This will build and publish the app to Google Cloud. In the end, you should see Publish Succeeded message in output window.
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.
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.
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.
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.
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.