What are We Doing

I’ve been a huge .NET fan since the days of .NET Framework 1.1. A number of years and upgrades later, Microsoft turned things up by introducing .NET Core and Visual Studio Code, allowing developers to write and run code from wherever we want without sacrificing productivity, security, or performance. If you’re asking the question, “Well, what does .NET Core do for me?”, then check this out. In a previous blog post, we built an API that shares photos via MMS backed by Dropbox cloud storage using C# and the .NET Framework 4.5. Let’s convert that API from targeting the .NET Framework to .NET Core.

How are We Doing This

To do this, we need to

If you haven’t read the original blog, create a Twilio account, a Dropbox developer account, and a Dropbox app with an App Folder as we’ll need those later on.

Step 1: Install Stuff

Grab .NET Core and Visual Studio Code first. If you’re already a .NET developer who uses Visual Studio, you are probably thinking, “wait can’t I use Visual Studio for this?” You absolutely can, but for this blog, let’s test drive Visual Studio Code.

After getting those things installed, fire up Visual Studio Code, hit ⌘ + P on your keyboard ( Ctrl + P if using Windows) and type the command ext install csharp . This should open the Extensions pane, and search for the C# extension. When the results come back, install the C# extension authored by Microsoft. You want the one that looks like the picture to the right. After clicking the Install and Reload buttons, we should be well on our way.

Step 2: Create Stuff

Working in Visual Studio Code is all about using folders and interacting with the command line. If you’re coming from Visual Studio you are probably feeling like I was after reading that last line. So let’s stop and acknowledge the feeling:

Now that we’ve got that out of the way, never fear! I promise you this is going to be easy and fast! So let’s start up the terminal in Mac (or Command Prompt in Windows). In that window, navigate to the directory where you’ll want to save this project and run the following commands:

mkdir CoreApi

cd CoreApi

dotnet new webapi



These commands create an ASP.NET Web API project in the folder CoreApi. Next let’s restore some Nuget packages that we used in our original project. To do that, go back to the terminal and type the following commands:

dotnet add package Twilio

dotnet add package Newtonsoft.JSON

dotnet restore

Since our project has been created, let’s open up Visual Studio Code by typing code . in the terminal. If you see a toolbar pop up in Visual Studio Code which says “Required assets to build and debug are missing from ‘CoreApi’’’, click on the Yes button. Doing this creates a .vscode folder that contains two files that VS Code uses to launch and debug our application. We’ll finally create the files we need by typing the commands below in our terminal:

code DropboxHelper.cs

code Controllers/PhotosController.cs

Then go to File > Save All to save our files and the photo to the right shows our completed setup.

Step 3: Modify Stuff

Now we typed up a bunch of commands and no code. Are you sad yet?

Hopefully not because it’s time to write some code. 😀

DropboxHelper.cs File

Head over to the original project’s DropboxHelper.cs file. Copy the code from there and paste it into the Helper.cs file in Visual Studio Code.

After copying the code over, PostAsJsonAsync will contain some errors because there is no .NET Core implementation for that method. To fix this, let’s make the following changes: