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. 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 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
Choose Github source control from available list of options
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)
Now Azure will start deployment from your repository to website
On your next step deployment to Azure will fail, it happen because Azure does not know what project need to be deployed.
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. 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
Let's try if our deployment was really successful and navigate to our website.
If you deployed azure from source code, it will fail for you with the following error
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
After checking-in code into Git repository deployment will be automatically started and after completing successfully your website is ready to use.