In this tutorial I will introduce you to GitHub Codespaces. We will first create an ASP.NET Core MVC application on your local computer. We will then push the application to GitHub. Once the application source code is on GitHub, we will use Visual Studio Code in GitHub Codespaces to modify the app and test it out - all in the cloud.
Companion video: https://youtu.be/DsGNAx_kJ3g
What is GitHub codespaces?
GitHub codespaces is an online development environment, hosted by GitHub and powered by Visual Studio Code. It allows you to develop entirely in the cloud. Codespaces is currently in limited public beta and subject to change.
You can signup for access to GitHub Codespaces at: https://github.com/features/codespaces/signup
Let's get started.
1) Create a repository in GitHub. I named mine MvcOnCodespaces.
2) Create an ASP.NET Core MVC application on your local computer. These are the commands I used to create the application named MvcOnCodespaces.
Create a directory for your application
Change to the directory you just created.
At the moment, the default version of .NET Core that is available on GitHub Codespaces is version 3.1. Therefore, to ensure that we create an application that uses .NET Core 3.1, we will create a global.json file specifying .NET Core version as follows:
dotnet new globaljson --sdk-version 3.1.401
NOTE: Find out the version of .NET Core 3.1 that exists on your computer using command:
Use the appropriate version in the 'dotnet new globaljson ..." command.
This was necessary for me to do because the default version of .NET Core on my computer was 5.0 at the time of writing this post.
Now we can create an ASP.NET Core MVC 3.1 app with:
dotnet new mvc
If you inspect your .csproj file, you will find that it, indeed, targets .NET Core 3.1 (netcoreapp3.1).
git initgit add .git commit -m "1st commit"
4) Create a Codespace. In your GitHub repository, click on Code followed by "Open with Codespaces".
On the next dialog, click on the "+ New codespace" button.
At the top right side you will see a progress bar that indicates that a Codespace is being prepared for you.