ASP.NET Core WebApi Baseline Step 1 – Bare Metal

ASP.NET Core WebApi Baseline Step 1 – Bare Metal

This is the first of several posts to come in which I plan to cover how and why I create a baseline ASP.NET Core WebApi project template. Whenever I go through the process of learning new technologies, like ASP.NET Core, my primary goal is to quickly learn their new features and capabilities, determine their strengths and weaknesses, and decide how best to implement some new patterns and practices using them. I am not necessarily promoting big architecture up front (BAUF), but neither would I would jump into a boat and push off from the shore without first checking for possible leaks, find the location of life preservers, look for a paddle, test the engine, etc. This initial learning process usually consumes a fair amount of my time, and I hope to reap benefits of my efforts for at least a few months. Once I feel comfortable with what I have learned, I create Visual Studio projects that contain the essential elements I personally feel are required in most of the web applications and web services I typically build. I then use these resulting projects as baselines from which to export reusable Visual Studio project templates. These project templates save me and my teammates a lot of time when setting up new instances of similar project types. They also help to facilitate pattern recognition among team members and help to encourage the use of similar approaches to building our applications.

In this post, we will create an empty web project (bare metal) and upgrade it to ASP.NET Core 1.1.0.

If you have not yet installed ASP.NET Core version 1.1.0, you must first do so. For more information, see my previous post called Install Developer Tools For ASP.NET Core.

Launch Visual Studio.

From the File menu, select the File->New->Project menu item.

new-project

The New Project dialog appears.

new-project-dialog-2

Navigate to the Installed->Templates->Visual C#->.NET Core folder.

In the middle window area, choose the ASP.NET Core Web Application (.NET Core) project template.

In the input form area at the bottom of the dialog, do the following:

For the Name field, enter AspNetCoreWebApiBaseline for the project name.

For the location field, enter or browse for a root folder location in which to create your solution folder.

Since I have already setup my local Git repository for this project, I will use the root folder location of C:\srcGit\aspnet-core-webapi-baseline\

Ensure the Create directory for solution checkbox is NOT checked.

Ensure the Create new Git repository checkbox is NOT checked.

Click the OK button.

The New ASP.NET Core Web Application (.NET Core) dialog box appears.

new-asp-net-core-web-application

In the Select a template pane, select the Empty template.

Do not change authentication at this time.

Ensure the Host in the cloud checkbox is NOT checked.

Click the OK button.

The new solution and web project appears in Solution Explorer window.

new-web-solution-for-webapi

Go ahead and run this web application right now.

Visual Studio launches your browser and displays the classic “Hello World!” text on the page.

Stop running the application.

Go ahead and check-in your source code at this time. After all, getting into the habit of frequently checking in your source code is a best practice for you and your team.

The initial preview version of the ASP.NET Core project templates in Visual Studio 2105 only creates new projects using the ASP.NET Core version 1.0.1 framework. We want to use the latest version 1.1.0 as of the time of this post, so let’s walk through how we can upgrade to the desired assembly versions.

Double-click on the project.json file to open it.

edit-asp-net-core-version-in-project-json

Update the versions as highlighted in the image above.

Microsoft.NETCore.App version 1.0.1 must be changed to 1.1.0

frameworks netcoreapp1.0 must be set to netcoreapp1.1

Save the project.json file.

Visual Studio automatically restores some (but not all) of the NuGet packages you need to update your application to ASP.NET Core version 1.1.0.

Let’s upgrade the remaining assemblies.

Right-click on the project and a context menu appears.

launch-manage-nuget-packages

Click on the Manage NuGet Packages… menu item.

The NuGet Package Manager dialog appears.

update-nuget-packages-1

Select the Updates tab.

Ensure the Include prerelease checkbox is checked.

Ensure the Select all packages checkbox is checked.

Click the Update button.

The Preview dialog appears allowing you to review the NuGet package updates you are about to make.

review-nuget-updates

Click the OK button.

The License Acceptance dialog appears.

license-accept

Click the I Accept button.

Visual Studio updates the remaining NuGet packages for you.

Rebuild the project and run it to ensure the website still works.

Let’s see what we have changed.

In the Visual Studio – Solution Explorer window, right-click on the project.json file.

A context menu appears.

compare-project-json-changes

Select the Compare with Unmodified… menu item.

The file DIFF dialog appears.

show-project-json-changes

Now you should see that all NuGet package files have been upgraded to ASP.NET Core version 1.1.0.

Go ahead and check-in your source code at this time.

At this point in the process, we have created a bare metal ASP.NET Core empty web project and have upgraded it to ASP.NET Core 1.1.0.

You can obtain the source code here.

You can find my other tutorials here.

In the next posts, I will add new features (the ones that I think are essential elements) to my baseline WebApi project.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s