Tuesday, 3 February 2015

Quick deploy to Azure Cloud Service using Web Deploy for web roles

Problem :
Recently we moved our Azure Web Site application to Azure Cloud Service and after that we were facing problems with huge deployment time. It used to take around 30 mins for each deploy (here we were deploying the cloud project). This is a known issue with Cloud Service as stated here.

Solution :
We were able to solve the problem by enabling web deploy for web role and publishing web role instead of deploying the entire cloud project all over again.

Steps to implement :
1. Right click on the cloud project and select Publish.

2. On the publish window, check the option boxes for "Enable Remote Desktop for all roles" and "Enable Web Deploy for all web roles" and set up user name and password for the same.



3. Click on Publish - this will be a complete cloud project deploy as before and as per settings, this will enable Remote Desktop for all roles and Web Deploy for all web roles.

4. If it asks for certificate, allow and save the certificate for future reference.

5. After publish is done, right click on the web role project and click Publish. You can also do some test changes before that to make sure the web deploy is working.

6. You can find the settings and connections are already populated for you. Just confirm things and click on Publish.




7. This will open up pop up for entering user name and password for web deploy. Provide the user name and password you did set up while enabling web deploy.



This will deploy the web role in much lesser time than the complete cloud project deployment. Actually, the time depends on the amount of changes you are going to deploy. If the changes are less, that will take lesser time to be published. You can also take advantage of file publish options for enabling pre-compilation Etc. 

Tuesday, 13 January 2015

Precompiling ASP.NET MVC views in Azure Cloud Service - RazorGenerator

Problem -

Recently, we moved our application from Azure Website to Cloud Service. In website, we were using pre-compilation as that gives a significant performance improvement. When we moved to cloud service and wanted to use pre-compilation, we found that this is not as easy as it was for website. For websites, we are having option in Visual Studio (a check box that you can check) to enable pre-compilation, but, Visual Studio does not provide any such option.

Solution -

One very easy and effective solution for this is to use RazorGenerator – a visual studio extension and a Nuget package (you need both).

Steps to implement -

Below are the steps to implement RazorGenerator for your ASP.NET MVC application -
  1. Install RazorGenerator from Visual Studio extension gallery.
  2. Install package RazorGenerator.mvc from Nuget package to your class library.
  3. Go to view > properties (you can get this by right clicking on the view file in solution explorer or pressing Alt + Enter).
  4. Set Custom Tool to RazorGenerator (you need to do the same for all existing views those you want to be precompiled).
  5. Save the property and you are done.



How this works -

When you set Custom tool to RazorGenerator, this will create a precompiled .cs file named [yourViewName].generated.cs, and the .cs file will be used when the application is running.