{"id":24725,"date":"2018-05-27T19:50:00","date_gmt":"2018-05-27T19:50:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/?p=24725"},"modified":"2019-02-14T20:18:06","modified_gmt":"2019-02-15T03:18:06","slug":"running-net-core-2-0-applications-in-a-linux-service-fabric-cluster-on-azure","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/running-net-core-2-0-applications-in-a-linux-service-fabric-cluster-on-azure\/","title":{"rendered":"Running .NET Core 2.0 applications in a Linux Service Fabric Cluster on Azure"},"content":{"rendered":"<p>In this post, Senior App. Dev. Managers <strong>Guru Satish Piduru<\/strong> and <strong>Mahendar Madhavaram<\/strong> explain how to deploy .NET Core 2.0 applications to a Linux Service Fabric Cluster.<\/p>\n<p>\n<hr>\n<p>The support for running .NET Core 2.0 applications in Service Fabric Cluster (SFC) environment on Linux is in preview mode today and general availability in the coming months. Today, stateless Service Fabric applications are supported in .NET Core 2.0 without any issues. If you are using Microsoft Visual Studio 2017 to develop Service Fabric applications, you can publish the applications directly to Azure SFC running on Windows but if you want to publish the applications to Azure SFC running on Linux, you may run into some issues depending on the project type and template that you choose to create an application.<\/p>\n<p>In this post, we will demonstrate how to deploy .NET Core 2.0 applications to a Linux SFC using scripts until Visual Studio IDE provides this capability. <\/p>\n<h3>Setup Local Service Fabric Cluster<\/h3>\n<p>To build and run Azure Service Fabric applications on your Windows development machine, install the Service Fabric runtime, SDK, and tools. You also need to enable execution of the Windows PowerShell scripts included in the SDK. <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-get-started\">Here<\/a> are instructions to setup your Windows development environment.<\/p>\n<h3>Setup Azure Service Fabric Cluster<\/h3>\n<p>If you haven\u2019t already, setup the Azure SFC on Linux using the Azure Portal. For the OS version, select \u2018UbuntuServer 16.04-LTS\u2019 as shown in the picture below. Please check the following <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-cluster-creation-via-portal\">documentation<\/a> for more information on all other settings.<\/p>\n<p><br><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image00221.jpg\"><img decoding=\"async\" width=\"454\" height=\"484\" title=\"clip_image002\" alt=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image002_thumb17.jpg\" border=\"0\"><\/a><\/p>\n<h3><br><\/h3>\n<h3>Walkthrough: .NET Core Stateless Service Fabric Application <\/h3>\n<p><strong>Step 1<\/strong>: In Visual Studio 2017, create a new Service Fabric Application<\/p>\n<p><em>New project &gt; Visual C# &gt; Cloud &gt; Service Fabric Application<\/em><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image00418.jpg\"><img decoding=\"async\" width=\"624\" height=\"484\" title=\"clip_image004\" alt=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image004_thumb16.jpg\" border=\"0\"><\/a><\/p>\n<p>Click OK to select a Template \u2018.NET Core 2.0 Stateless Service\u2019<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image00618.jpg\"><img decoding=\"async\" width=\"637\" height=\"484\" title=\"clip_image006\" alt=\"clip_image006\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image006_thumb17.jpg\" border=\"0\"><\/a><\/p>\n<p><strong>Step 2<\/strong>: Update the Runtime Identifier to linux-x64<\/p>\n<p>Open all the service .<b>csproj<\/b> files and update the RuntimeIdentifier as shown below<\/p>\n<blockquote>\n<p>&lt;PropertyGroup&gt;<\/p>\n<p>&lt;OutputType&gt;Exe&lt;\/OutputType&gt;<\/p>\n<p>&lt;TargetFramework&gt;netcoreapp2.0&lt;\/TargetFramework&gt;<\/p>\n<p>&lt;IsServiceFabricServiceProject&gt;True&lt;\/IsServiceFabricServiceProject&gt;<\/p>\n<p>&lt;RuntimeIdentifier&gt;linux-x64&lt;\/RuntimeIdentifier&gt;<\/p>\n<p>&lt;\/PropertyGroup&gt;<\/p>\n<\/blockquote>\n<p><br><\/p>\n<p><strong>Step 3<\/strong>: Update the ServiceManifest.xml to remove <b>.exe <\/b>extension from Stateless1.exe to Stateless1 as shown below<\/p>\n<blockquote>\n<p>&lt;CodePackage Name=&#8221;Code&#8221; Version=&#8221;1.0.0&#8243;&gt;<\/p>\n<p>&lt;EntryPoint&gt;<\/p>\n<p>&lt;ExeHost&gt;<\/p>\n<p>&lt;Program&gt;Stateless1&lt;\/Program&gt;<\/p>\n<p>&lt;\/ExeHost&gt;<\/p>\n<p>&lt;\/EntryPoint&gt;<\/p>\n<p>&lt;\/CodePackage&gt;<\/p>\n<\/blockquote>\n<p>Note: If you are building for Windows, the entry point is Stateless1.exe but since you\u2019re building for Linux, it\u2019s not going to produce a Windows EXE file. Therefore, we have to change that in the ServiceManifest.xml to the binary output file that\u2019s being built for Linux (usually it\u2019s the same file name but without the .exe extension). <\/p>\n<p><strong>Step 4<\/strong>: Right click on the Project and click Publish. In the Publish Service Fabric Application wizard, select the Endpoint for SFC cluster and then click Publish.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image002110.jpg\"><img decoding=\"async\" width=\"644\" height=\"454\" title=\"clip_image002[1]\" alt=\"clip_image002[1]\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image0021_thumb1.jpg\" border=\"0\"><\/a><\/p>\n<p>You can login to the Azure Portal, select Service Fabric Cluster, and verify if the application is deployed successfully.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image01012.jpg\"><img decoding=\"async\" width=\"644\" height=\"78\" title=\"clip_image010\" alt=\"clip_image010\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image010_thumb11.jpg\" border=\"0\"><\/a><\/p>\n<h3><br><\/h3>\n<h3>Walkthrough: ASP.NET Core Stateless Service Fabric Application <\/h3>\n<p><strong>Step 1<\/strong>: In Visual Studio 2017, create a new &#8220;out of the box&#8221; Service Fabric Application<\/p>\n<p><em>New project &gt; Visual C# &gt; Cloud &gt; Service Fabric Application<\/em><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image0115.jpg\"><img decoding=\"async\" width=\"623\" height=\"484\" title=\"clip_image011\" alt=\"clip_image011\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image011_thumb5.jpg\" border=\"0\"><\/a><\/p>\n<p>Click OK to select a Template \u2018Stateless ASP.NET Core\u2019<\/p>\n<p><b><\/b><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image0134.jpg\"><img decoding=\"async\" width=\"642\" height=\"484\" title=\"clip_image013\" alt=\"clip_image013\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image013_thumb4.jpg\" border=\"0\"><\/a><b><\/b><\/p>\n<p>Click on \u2018Web Application (Model-View-Controller)\u2019<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image0155.jpg\"><img decoding=\"async\" width=\"644\" height=\"424\" title=\"clip_image015\" alt=\"clip_image015\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image015_thumb4.jpg\" border=\"0\"><\/a><b><\/b><\/p>\n<p><strong>Step 2<\/strong>: Update the Runtime Identifier to linux-x64<\/p>\n<p>Open all the service <b>.csproj<\/b> files and update the RuntimeIdentifier as shown below<\/p>\n<blockquote>\n<p>&lt;PropertyGroup&gt;<\/p>\n<p>&lt;OutputType&gt;Exe&lt;\/OutputType&gt;<\/p>\n<p>&lt;TargetFramework&gt;netcoreapp2.0&lt;\/TargetFramework&gt;<\/p>\n<p>&lt;IsServiceFabricServiceProject&gt;True&lt;\/IsServiceFabricServiceProject&gt;<\/p>\n<p>&lt;RuntimeIdentifier&gt;linux-x64&lt;\/RuntimeIdentifier&gt;<\/p>\n<p>&lt;\/PropertyGroup&gt;<\/p>\n<\/blockquote>\n<p><strong>Step 3<\/strong>: Update the ServiceManifest.xml to remove <b>.exe<\/b> extension from Stateless1.exe to Stateless1 as shown below<\/p>\n<blockquote>\n<p>&lt;CodePackage Name=&#8221;Code&#8221; Version=&#8221;1.0.0&#8243;&gt;<\/p>\n<p>&lt;EntryPoint&gt;<\/p>\n<p>&lt;ExeHost&gt;<\/p>\n<p>&lt;Program&gt;Web1&lt;\/Program&gt;<\/p>\n<p>&lt;\/ExeHost&gt;<\/p>\n<p>&lt;\/EntryPoint&gt;<\/p>\n<p>&lt;\/CodePackage&gt;<\/p>\n<\/blockquote>\n<p><strong>Step 4<\/strong>: Click on Publish won\u2019t work like it did in example \u2018.NET Core Stateless Service\u2019 above. This has to do with an issue in VS packaging for Linux for ASP.NET Core projects. As noted above, this will be fixed in an upcoming release.<\/p>\n<p>Here are the steps which should work using <b>dotnet<\/b> commands to publish.<\/p>\n<ol>\n<li>Only use VS to create application package structure, right click on Applciation3 in solution explorer and select Package. This will create application package structure at <b><i>c:\\user\\source\\Application3\\Application3\\pkg\\Debug<\/i><\/b>\n<li>Open Command Prompt, cd to the directory containing the AspNetCore <b>.csproj<\/b> (<b><i>c:\\user\\source \\Application3\\Web1<\/i><\/b>) and run following commands:<\/li>\n<\/ol>\n<blockquote>\n<p><b>dotnet build<\/b><\/p>\n<p><b>dotnet publish &#8211;self-contained -r ubuntu.16.04-x64 -o <\/b><b>c:\\user\\source \\Application3\\Application3\\pkg\\Debug\\Web1Pkg\\Code<\/b><\/p>\n<\/blockquote>\n<p><strong>Step 5<\/strong>: Now use Service Fabric PowerShell to create the application.<\/p>\n<ol>\n<li>Connect-ServiceFabricCluster mmlinuxsfc.eastus.cloudapp.azure.com:19000 (Provide security credentials if its secured cluster)\n<li>Copy-ServiceFabricApplicationPackage -ApplicationPackagePath c:\\user\\source \\Application3\\Application3\\pkg\\Debug -ApplicationPackagePathInImageStore pkg_app3_cmd\n<li>Register-ServiceFabricApplicationType -ApplicationPathInImageStore pkg_app3_cmd\n<li>New-ServiceFabricApplication -ApplicationName&nbsp; fabric:\/Application3Type -ApplicationTypeName Application3Type -ApplicationTypeVersion 1.0.0<\/li>\n<\/ol>\n<p>Note: Register-ServiceFabricApplicationType occasionally times out. Use compression flag for faster uploads.<\/p>\n<p>If Step 5 runs successfully, Application3 should be installed in SFC.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image0171.jpg\"><img decoding=\"async\" width=\"644\" height=\"100\" title=\"clip_image017\" alt=\"clip_image017\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image017_thumb1.jpg\" border=\"0\"><\/a><\/p>\n<p>If the Application3 failed to upload or times out, you can use Azure Service Fabric CLI command, sfctl to upload the application. You can install the Azure Service Fabric CLI from <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-cli\">https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-cli<\/a><\/p>\n<p>After using the \u201csfctl application upload\u201d and \u201csfctl application provision\u201d. The ASP.NET 2.0 MVC service, is deployed to Linux SFC and healthy. <\/p>\n<blockquote>\n<p><b>C:\\users\\pathwherphythoninstalled&gt;sfctl<\/b><\/p>\n<p><b>application upload &#8211;path <\/b><b>c:\\user\\source \\Application3\\Application3<\/b><b>\\pkg\\Debug &#8211;show-progress<\/b><\/p>\n<p><b>C:\\users\\pathwherphythoninstalled&gt;sfctl<\/b><\/p>\n<p><b>application provision &#8211;no-wait &#8211;application-type-build-path Debug<\/b><\/p>\n<\/blockquote>\n<p>Note: if Application has references to other project which has reference to NuGet packages, use the following workaround:<\/p>\n<p>Compile the above project using the below command and save these binaries:<\/p>\n<blockquote>\n<p>1. dotnet publish -c Release -r linux-x64<\/p>\n<p>2. In Visual Studio, compile the Service Fabric project to generate the binaries<\/p>\n<p>3. Replace the generated binaries with the ones generated in #1<\/p>\n<p>4. Use SF CLI to upload the binaries and create the application<\/p>\n<\/blockquote>\n<p>The application that has NuGet package reference has successfully started in the SF cluster<\/p>\n<h3>References<\/h3>\n<ul>\n<li>Overview of Azure Service Fabric: <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-overview\">https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-overview<\/a><\/li>\n<li>Azure Service Fabric Core SDK: <a href=\"https:\/\/www.microsoft.com\/web\/handlers\/webpi.ashx?command=getinstallerredirect&amp;appid=MicrosoftAzure-ServiceFabric-CoreSDK\">https:\/\/www.microsoft.com\/web\/handlers\/webpi.ashx?command=getinstallerredirect&amp;appid=MicrosoftAzure-ServiceFabric-CoreSDK<\/a><\/li>\n<li>Is it being deployed on ubuntu? If yes are you using Runtime identifier for ubuntu as per <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/rid-catalog#linux-rids\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/rid-catalog#linux-rids<\/a><\/li>\n<li>Could you add the entry point as <a href=\"https:\/\/github.com\/amanbha\/samples\/blob\/netcore10\/ContainerDemo\/WebFront\/PackageRoot\/ServiceManifest_Linux.xml#L17\">https:\/\/github.com\/amanbha\/samples\/blob\/netcore10\/ContainerDemo\/WebFront\/PackageRoot\/ServiceManifest_Linux.xml#L17<\/a><\/li>\n<li>Add entrypoint.sh as <a href=\"https:\/\/github.com\/amanbha\/samples\/blob\/netcore10\/ContainerDemo\/WebFront\/entryPoint.sh\">https:\/\/github.com\/amanbha\/samples\/blob\/netcore10\/ContainerDemo\/WebFront\/entryPoint.sh<\/a> in your code package.<\/li>\n<li>Deploy an Azure Service Fabric Linux container application on Azure <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-quickstart-containers-linux\">https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-quickstart-containers-linux<\/a><\/li>\n<li>Deploy an Azure Service Fabric Windows container application on Azure <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-quickstart-containers\">https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-quickstart-containers<\/a><\/li>\n<li>Azure SF PowerShell samples: <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-powershell-samples\">https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/service-fabric-powershell-samples<\/a><\/li>\n<li>Azure SF CLI samples: <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/samples-cli\">https:\/\/docs.microsoft.com\/en-us\/azure\/service-fabric\/samples-cli<\/a><\/li>\n<\/ul>\n<p><br><\/p>\n<hr>\n<p><a href=\"https:\/\/blogs.msdn.com\/b\/premier_developer\/archive\/2014\/09\/15\/welcome.aspx\"><strong>Premier Support for Developers<\/strong><\/a> provides strategic technology guidance, critical support coverage, and a range of essential services to help teams optimize development lifecycles and improve software quality.&nbsp; Contact your Application Development Manager (ADM) or <a href=\"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/contact-us\/\"><b>email us<\/b><\/a> to learn more about what we can do for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, Senior App. Dev. Managers Guru Satish Piduru and Mahendar Madhavaram explain how to deploy .NET Core 2.0 applications to a Linux Service Fabric Cluster. The support for running .NET Core 2.0 applications in Service Fabric Cluster (SFC) environment on Linux is in preview mode today and general availability in the coming months. [&hellip;]<\/p>\n","protected":false},"author":582,"featured_media":37840,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25],"tags":[27,31],"class_list":["post-24725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","tag-linux","tag-service-fabric"],"acf":[],"blog_post_summary":"<p>In this post, Senior App. Dev. Managers Guru Satish Piduru and Mahendar Madhavaram explain how to deploy .NET Core 2.0 applications to a Linux Service Fabric Cluster. The support for running .NET Core 2.0 applications in Service Fabric Cluster (SFC) environment on Linux is in preview mode today and general availability in the coming months. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/24725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=24725"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/24725\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/37840"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=24725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=24725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=24725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}