Skip to content

Tutorial 02 02 Creating a Basic Solution

mattl91 edited this page Mar 13, 2023 · 11 revisions

Harmony Core Logo

Creating a Basic Solution

Using the harmonycore template is a quick way to create a basic development environment for a Harmony Core service that you can customize to meet your needs, and it is the starting point for this tutorial, which takes you through the process of building a fully functional Harmony Core service, step by step.

VIDEO: Creating a Basic Solution

Creating a Solution

In the following steps, you will create a new Visual Studio solution from the harmonycore template. This template provides the overall solution and project infrastructure needed to create a custom Harmony Core service, and it includes all the project and NuGet package references you might need. But initially it has no pre-generated code, and Harmony Core settings (set with the Harmony Core CLI tool) are all at their defaults.

To create a new solution:

  1. Open a Windows command prompt and move to the location where you would like the solution to be created.

  2. Use the following dotnet command to make sure the Harmony Core templates (including harmonycore) are installed on your machine and that you have the latest version of these templates:

    dotnet new install Harmony.Core.ProjectTemplates
    

If the Harmony Core project templates are not already installed on your machine, you should see a series of messages starting with Restore completed in....

The command line dotnet tool is also used to create new projects and solutions from pre-installed templates when used with this syntax:

dotnet new harmonycore [-o <folderName>] [-n <solutionName>]

By default, the solution will be created in the current folder. However, you can use the optional -o <folderName> to create a new subfolder for the solution. And by default, the name of the new solution will be the same as the name of the containing folder, but you can override this with the -n <solutionName> option.

  1. Create a new solution with the following command:

    dotnet new harmonycore -o MyApi
    

You should see various messages like these scroll by as the solution is created:

The template "Harmony Core Starter Solution" was created successfully.

Processing post-creation actions...
Restoring C:\hc\tut\MyApi\MyApi.sln:
Determining projects to restore...
Restored C:\hc\tut\MyApi\Services\Services.synproj (in 1.33 sec).
Restored C:\hc\tut\MyApi\Services.Isolated\Services.Isolated.synproj (in 1.33 sec).
Restored C:\hc\tut\MyApi\Services.Controllers\Services.Controllers.synproj (in 1.33 sec).
Restored C:\hc\tut\MyApi\Services.Host\Services.Host.synproj (in 1.33 sec).
Restored C:\hc\tut\MyApi\Services.Models\Services.Models.synproj (in 28 ms).
Restore succeeded.
Restoring C:\hc\tut\MyApi\Repository\Repository.synproj:
Determining projects to restore...
Nothing to do. None of the projects specified contain packages to restore.
Restore succeeded.
Restoring C:\hc\tut\MyApi\Services\Services.synproj:
Determining projects to restore...
All projects are up-to-date for restore.
Restore succeeded.
Restoring C:\hc\tut\MyApi\Services.Controllers\Services.Controllers.synproj:
Determining projects to restore...
All projects are up-to-date for restore.
Restore succeeded.
Restoring C:\hc\tut\MyApi\Services.Host\Services.Host.synproj:
Determining projects to restore...
All projects are up-to-date for restore.
Restore succeeded.
Restoring C:\hc\tut\MyApi\Services.Isolated\Services.Isolated.synproj:
Determining projects to restore...
All projects are up-to-date for restore.
Restore succeeded.
Restoring C:\hc\tut\MyApi\Services.Models\Services.Models.synproj:
Determining projects to restore...
All projects are up-to-date for restore.
Restore succeeded.

Unlike when using the harmonydemo template, the code in the projects generated by the harmonycore template is not complete and will not be in a buildable form until you have configured the environment, generated some code, and added that code to various projects. Typically, you will proceed in Visual Studio from this point on.

Opening the Solution in Visual Studio

Having used the dotnet command-line tool to create your new development solution, you can now work in Visual Studio:

  1. Start Visual Studio 2022.

  2. Use the Open a Project or Solution option to open the new solution.

  3. Go to Solution Explorer. If you can't see Solution Explorer, select View > Solution Explorer from the menu.

  4. If the contents of the Solution Explorer are expanded, start by clicking the Collapse All button on the Solution Explorer toolbar.

You should see something like this:

Solution Explorer

Customizing the Service

You have just created a "shell" environment into which you can start adding various types of data-centric or code-centric RESTful web service endpoints. The direction you take from this point will depend on your requirements, but to get a good basic understanding of how Harmony Core services are built and work, we recommend going through the remaining sections of this tutorial step by step.


Next topic: Enabling OData Support


Clone this wiki locally