Over a million developers have joined DZone.

Create or Convert Your Service Fabric Microservices To .Net Core xproj Structure

Today we’ll discuss how we can create a new .Net Core Service Fabric Microservice targeting the full stack (.net46).

· Integration Zone

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

In a previous article, we walked through the process of hosting our Asp.Net Core Web Microservice within Service Fabric and also self-hosting outside Service Fabric via Kestrel for development and debugging. Today we’ll discuss how we can create a new .Net Core Service Fabric Microservice targeting the full stack (.net46), given the VS 2015 template only supports web projects currently.

Note that similar principles would apply to converting existing Microservice projects to .Net Core xproj structure. 

To begin, in Visual Studio 2015 add a new Service Fabric Project, in my example a Stateful Service named AcmeService:

Image title

Once complete you should have a solution resembling the below:

Image title

What we do next is remove the AcmeService project from the solution altogether and rename the folder to AcmeService.tmp. We will re-create the project as a .Net Core Console Application. Select Add New Project and select Console Application (.Net Core), making sure the location is the same as the original and enter AcmeService as the project name:
Image title
From the AcmeService.tmp folder copy:

PackageRoot folder
Properties folder
AcmeService.cs (copy over target file)

to the AcmeService folder, your solution resembling:

Image title
Copy the contents of the below into your project.json file:

    "title": "AcmeService",
    "description": "AcmeService",
    "copyright": "Copyright © Acme 2016",
    "version": "1.0.0-*",

    "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true,
        "compile": {
            "exclude": [

    "dependencies": {
        "Microsoft.ServiceFabric": "5.1.150",
        "Microsoft.ServiceFabric.Services": "2.1.150"

    "frameworks": {
        "net46": { }

    "runtimes": {
        "win7-x64": { }


Lastly, we have to add back our .Net Core Console Application project by right clicking on the Service Fabric project and selecting Add Existing Service Fabric Service. You might get a warning about updating but just click OK. You can also delete the AcmeService.tmp folder as it’s no longer needed.

To compile you can use Visual Studio or at a command prompt you can issue normal dotnet.exe commands, for example:

dotnet.exe build

In the next series of articles we’ll look at some more advanced topics such as sharing appsettings.json files between Web and other Microservice projects, as well as logging to Application Insights.

Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

asp.net core ,microservices ,service fabric ,microsfot

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}