Xperience by Kentico and Microsoft Azure are very powerful together. When some of the out of the box features don't work, it can cause a lot of problems, for a long time. Read on to find out what we did to resolve a build issue in an Azure Web App connected to Bitbucket.
Problem
We recently (about a year ago) started deploying Xperience as a web app vs. a web site. If you want to learn more about benefits of either, check out this article. Converting to MVC development from Portal Engine helped us with this decision as I'm sure it will you as well. One of the first deployments we did on MVC and Xperience as a Web App the deployment failed horribly. After some time we decided to give up and deploy the site via FTP.
Let me back up a bit here and give you some context. This project is an Xperience version 12 site in MVC. The site is hosted in an Azure Web App. The code is stored in a Bitbucket repo. We use Visual Studio Pro 2019 for the local build. The plan was to deploy the site to Azure using the Deployment Center and Bitbucket.
Typically with any Git repo you have a gitignore file. Our ignore file was no different than any other project we had set up with the exception of excluding the entire BIN directory. Here's the content of our ignore file:
.vs/
CMS/App_Data/Persistent/
CMS/App_Data/AzureCache/
CMS/App_Data/AzureTemp/
CMS/App_Data/CMSTemp/
CMS/App_Data/CMSTemp/ImportExport/
CMS/App_Data/CMSModules/DeviceProfiles/logFiftyOne.txt
CMS/bin/
CMS/CMSSiteUtils/Export/
packages/
Pretty simple ignore file if you ask me. Essentially we wanted the MSBuild process to use the .csproj file to get all the packages and deploy the site without the need to store those packages and other large dlls in the Bitbucket repo.
Fast forward to the ACTUAL problem now! The Deployment Center is configured and working properly with Bitbucket credentials and the proper repository and branch. Clicking on the Continue button will kick the Kudu build and deployment process into gear. After about 5 or 6 minutes the process failed. The errors in the log file were very odd considering this was a base Xperience install. Thelocal build process didn't capture ANY of the errors below.
If you look at the file locations and the errors, they are base Kentico files complaining about missing commas and such. So looking into the issues more, I double checked the files locally and verified there were no syntax issues.
I spent between 2-3 weeks researching the issue and what was causing it. The number of Google searches I performed and the combination of keywords was crazy! I contacted Kentico Support and they had no record of any issue like this and suggested reaching out to Azure Support.
SOLUTION - WEB APP KEY TO THE RESCUE!
The actual problem is Kudu, by default, uses MSBUILD14. There's a question out on StackOverflow asking how you force Kudu to use MSBUILD15. My searches lead me to this article at one time prior to reaching out to Kentico and Azure. I even implemented the AppSetting key as they suggested with no success. Little did I know this was the actual problem but I finally got tired of the work arounds and reached out to Kentico and Microsoft again and this was the solution we came up with.
Are you ready for the actual fix yet? You're going to be as upset as I was because it's a VERY simple fix and has to do specifically with the steps in which you perform the set up of the Azure Web App and the Deployment Center connection. Follow these steps to ensure your Web App builds properly using Kudu and the Deployment Center:
- Create an Azure Web App.
- Add the MSBUILD_PATH key and value to the web app's configuration settings.
- Connect Bitbucket or GitHub to your web app using the Deployment Center.
- Watch your website build and deploy.
The biggest problem I had initially was I already had steps 1 and 3 completed and attempted to add step 2 in after step 3. At this time, it's too late and the Kudu script is already created and won't regenerate. So you have to remove the deployment connection, add the key and value in to the app settings and hook up the deployment connection again.
Final Thoughts
Needless to say, we put up with the workaround process for the last 12 months or so. We finally got tired of it and after a month of working with Microsoft and Kentico Support we were able to figure the problem out. I had a gut feeling it was a simple issue but didn't know it would be the issue I had initially looked at over 12 months ago.
Hopefully at least 1 person benefits from this and it saves them all the pain and suffering it caused me!
Best of luck and and Happy Coding!