• Home /
  • Blog /
  • Deploying Orchard CMS from source code hosted at Github to Microsoft Azure
Orchard Cms

Deploying Orchard CMS from source code hosted at Github to Microsoft Azure

Microsoft Azure provides a cool feature: deploying application from source code, which is especially useful for small projects where creating a build server does not make sense due to complexity or price. But for a small projects, like a personal website Azure deployment from source code saves a lot of time and efforts.

In this post you will get an idea how to deploy Orchard CMS project to Microsoft Azure website from source code hosted on Github.

I seen a couple of tutorials related to deploying Orchard CMS to Azure, but they are too old and does not explain what issues you can face with current version of Orhcard and how to solve them, especially when you deploying from code. Let's start from scratch.

Orchard CMS from Github repository

In order to begin working on Azure deployment you need to create project in Github, you can use your own private repository or just fork Orchard CMS from there https://github.com/OrchardCMS/Orchard (dev branch) and keep it public. forking Orchard CMS Github repository I always use source code for my websites, because it's easy to do additional development and look how orchard done inside, but all steps below will work with compiled version of Orchard CMS as well.

I am not going to explain in much details how to create a new website in Azure, it's very simple task and there are a lot of documentation on Microsoft website. I used "Quick Create" option like on image below how to create azure website Now, after you have your website running, we can start with setting up deployment from source code for your website.

Setting up deployment from Github to Azure website

In order to setup deployment from Github to Azure website you need to follow the steps below.

Setup deployment from source control setup deployment from source control

Choose Github source control from available list of options choose Github source control

Now you may be asked to authorize Azure to access Github, in my case I already did it before, so skipping this step.

Choose Github repository (you can choose both public and private repository) choose Github repository to deploy to azure

Now Azure will start deployment from your repository to website deployment starts from Github to Azure

On your next step deployment to Azure will fail, it happen because Azure does not know what project need to be deployed. azure deployment fail

But we can let Azure know what project to choose, there are two ways to tell this to Azure. First is to add .deployment file to the root of your source code repository and add path to your project

 [config]  project = src\Orchard.Web\Orchard.Web.csproj 

Second option is to add AppSetting inside of Azure Configuration page with the name of the project to build and deploy. how to let Azure know what project need to be deployed Personally I prefer second option, it's more easy for me, beside if you have multiple projects in the same solution, for example WEB API project and ASP.NET MVC project, you want be able to use .deployment file to deploy both projects.

Now deployment should be successful successful deployment to azure from Github

Let's try if our deployment was really successful and navigate to our website. open azure website

If you deployed azure from source code, it will fail for you with the following error orchard cms fail to start

Server Error in '/' Application.  None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Orchard.Environment.DefaultOrchardShell' can be invoked with the available services and parameters: Cannot resolve parameter 'Orchard.Mvc.Routes.IRoutePublisher routePublisher' of constructor 'Void .ctor(System.Func`1[Autofac.Features.OwnedInstances.Owned`1[Orchard.Environment.IOrchardShellEvents]], System.Collections.Generic.IEnumerable`1[Orchard.Mvc.Routes.IRouteProvider], System.Collections.Generic.IEnumerable`1[Orchard.WebApi.Routes.IHttpRouteProvider], Orchard.Mvc.Routes.IRoutePublisher, System.Collections.Generic.IEnumerable`1[Orchard.Mvc.ModelBinders.IModelBinderProvider], Orchard.Mvc.ModelBinders.IModelBinderPublisher, Orchard.Tasks.ISweepGenerator, System.Collections.Generic.IEnumerable`1[Orchard.Owin.IOwinMiddlewareProvider], Orchard.Environment.Configuration.ShellSettings)'.  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.   

It happens because Orchard Modules are not compiled, and you can verify it by accessing your website using FTP and opening any module in Modules folder, the bin folder will not be there.

So we need to fix it and make all our modules compile during deployment process. The simplest way to do it is to modify Orchard.Web.csproj file and compile all modules. Add the following target to the end of the file

<target     name="BuildAllModules">     <itemgroup>         <allmodules include="$(ProjectDir)Modules\**\*.csproj" exclude="$(ProjectDir)Modules\**\*Tests*.csproj">         </allmodules>         <orchardmodules include="$(ProjectDir)..\Orchard\**\Orchard.Framework.csproj"></orchardmodules>     </itemgroup>     <msbuild projects="@(OrchardModules)" targets="Build" properties="Configuration=$(Configuration);"></msbuild>     <msbuild projects="@(AllModules)" targets="Build" properties="Configuration=$(Configuration);"></msbuild> </target> 

and call that target

<calltarget targets="BuildAllModules"></calltarget>

changes to Orchard CMS project What is happening there is: first I build Orchard.Framework.dll, that dll used by many Orchard modules and second building all Orchard modules, but excluding Test projects (tests are fail to build)

After checking-in code into Git repository deployment will be automatically started and after completing successfully your website is ready to use. Orchard CMS deployed successfuly to Azure Orchard CMS ready to use after deployment from git to Azure

Yaplex - Freelance developer - white logo on black background

Yaplex ® is a custom software development company located in Mississauga, Ontario. Yaplex was founded in 2013 and provides website development, mobile development, and custom .NET software development services.

Contact Information

Mississauga, ON, Canada
Phone: +1 647 328 3809
Email: hello@yaplex.com