Showing posts with label MSBuild. Show all posts
Showing posts with label MSBuild. Show all posts

Thursday, January 19, 2012

Continuous Integration( Part Four) : Deploy Web Application to a Remote machine Using MSDEPLOY

As I mentioned in my previous blog bost  there is a better option for deploy a web application in to a IIS location through MSDeploy command line tool rather than using XCOPY. In this post I am going to brief the issues I encounter during web deployment phase and the steps I followed to overcome them.

Issue 1:
When I package my web application from my local machine it creates a MVC-Client.deploy.cmd file which is referring MSDepoly path as :
                 MSDeployPath="C:\Program Files\IIS\Microsoft Web Deploy V2\"
But In the build server machine (Locate in same network) it creates a MVC-Client.deploy.cmd file which has MSDepoly path as
                MSDeployPath="C:\Program Files (x86)\IIS\Microsoft Web Deploy\"

And I have both versions of MS Web Deploy installed on both machines. But there was an issue when I try to deploy web application to the the web server from the build server machine.
                MVC-Client.deploy.cmd /y /M:es-websrv01/MSDeployAgentService
Reason is it refers version 1 instead of version 2. And I can garentee you that I have same MSBuild versions in both my local machine and build server machine. I dig a bit about this issue and I found that we need to install VS2010 service pack one to generate the working MVC-Client.deploy.cmd file. In my development machine i had it and on the build server machine it has not installed. Installing VS2010 service pack 1 fixed this issue.

Issue 2:
Permission Issue
In my case Jenikings is running as a windows service which initiates by a local user(Not In the Active Domain) in the build server machine(Windows NT ). But in order to do the remote deployment that user should have admin privileges in the target remote machine(es-websrv0). So what I did is just add a user in to the AD with the admin privileges for es-websrv0 and did the deployment. 

Another permission issue I encounter is we cant do the remote deployment from the Programs files folder in C:/ since it has special permission level.  

Issue 3:
Required Softwares which should be installed in target web server machine.
As I notice there are two ways of do the remote deployment as follows make sure that you have installed corresponding soft-wares on the destination machine.
M: Destination server name or Service URL
    If this flag is not specified, the package is installed on the computer where the command is run. The Service URL can be in the following format:
        https://:8172/MSDeploy.axd
    This format requires that IIS 7 be installed on the destination server and that IIS 7 Web Management Service(WMSvc) and Web Deployment Handler be set up.


    The service URL can also be in the following format:
        http:///MSDeployAgentService
    This format requires administrative rights on the destination server, and it requires that Web Deploy Remote Service (MsDepSvc) be installed on the destination server. IIS 7 does not have to be installed on the destination server.

Saturday, January 14, 2012

Continuous Integration( Part Two) :Web Config Transformation


Note : In this post I will use Microsoft based technologies. But the main concept describes in a general manner.

In my previous post I mentioned that a build server should run the tests with its configurations(eg: data base connection strings) and if the test are successful then it should deploy working packages in to many web container location according to your requirement.For an example it should deploy a working package in to productions server as well as in to the live server with their specific configurations.(both application are pointing their own data bases)

production server => production database with tests data for QA guys
Live Server => live data base with the actual data 

In order to do this, build server has to create several packages with different configurations and deploy them in to required locations.There are many packaging tools which facilitate configuration transformation functionality.In this post I will use MSBuild command line tool to create IIS deployable packages.Before Moving on we need to know a bit detail knowledge about web config transformation.

If you have a close look in to your web.config file which created by VS2010 you will notice that there are two config files which named as web.Debug.config and web.release.config. Those two files default files which offer by VS2010.If you want your own you can add since VS2010 provides you an extensible configuration setting environment.

                          Build =>Configuration Manager  => Add your own configuration 

Lets assume we have created configuration for our production server which I mentioned above.Till you cant see it your latest configuration setting appears on web.config file. In order to set it you should do following step.

                         right click the original web.config file and click the context menu command “Add Config Transforms” 
In the Web.BuildServer.config file you can write specific settings which is specific to the build Server settings. Following is the way we do the we web.config transformation. 

 

    
      
     
   

You can see here we have used XML Transformation Engine which does the actual task when we package our project with build Server configurations.Followings are the some of functionality offer by transformation engine.


Other than the xdt:Transform tag you can see we have used a locator which refer the original web.config configurations. 
And following is the MSBuild command which we can transform web.config which has the build server configurations. 

                   /t:TransformWebConfig /p:Configuration=BuildServer" 

Also you can create your web deployment package with the build server settings by following MSBuild command.

           "ProjectName.csproj" /T:Package/P:Configuration=BuildServer;

It creates a ZIP file which has batch file which can be executed from MSDepoly command line tool.And also we can see transformed and original web.config files. Here we have a small problem.That is if we manually unzip this created zip file and then manually copy to the IIS location . then build server specific settings are not applying to it.Since in web.config file refers the transform elements from a external XML file which is used by the MSDeploy command and it is the task of MSDeploy tool to read the external XML property file and replace the matching tokens. So if you do the deployment manually I recommend you to copy the transformed web.config and replace the existing web.config file in the package.Then you can manually copy  package in to the IIS location and your app will work since now you have the build server configurations.

Ok.Now we should back to our main topic again which is Continuous Integration. If we can use above concept in the build server side (through a build server job) we can create a package in build server machine with its specific configurations and then deploy it. Also we can use same strategy for multiple deployment with many configurations.And my next post will describe how we can achieve this task. I hope to use jenkins build server and some of its plugins to do it.