Showing posts with label Packaging. Show all posts
Showing posts with label Packaging. Show all posts

Thursday, July 09, 2009

10 + 20 Reasons why you should Create a Web Package

Before we talk about the reasons why you should create a Web Package let us first understand what is a web package… Web Package is an atomic, transparent, self describing unit representing your web application which can be easily hydrated into any IIS Web server to reproduce your web…  It is a .zip file which not only contains your content but also contains its dependencies like IIS Settings, Databases, GAC DLLs, Registry Keys etc…

The concept of creating Web Packages for deploying your web application to an IIS Web Server is recently introduced with Microsoft Web Deployment Tool (MsDeploy) and towards the end of this post I will talk about how you can create a Web Package for your web app… But before going there let me talk about the 10 reasons why you should consider creating web packages for your web application:

  1. Having all your web content and dependencies like IIS Settings & DB into a single .zip file allows you to easily transport it anywhere…
  2. If the web package actually contains source code then you can replicate your dev environment to another box relatively easily…  Imagine being able to recreate a project on your home machine by simply emailing yourself a .zip file…
  3. If you are deploying in a web farm environment then deploying the web package to various server boxes will allow you to very easily recreate your load balanced web servers…
  4. If you are creating software for community to use then sharing web package .zip files with world creates a common handshake model…
  5. Web Application Gallery, which will be common home to find reusable Web Applications also uses the same Web Package format… So you will have an opportunity to put up your web app into Web Application Gallery if you create a Web Package…
  6. Most of the Package creation process is very automated so you do not need to write custom actions like you would have to do in case of MSIs…
  7. Creation of Web Packages can be automated along with your nightly builds really easily using MsBuild with systems like Team Build…
  8. You can create a web package for various versions of your web application and easily use the versioned packages to roll back to any version you like…
  9. You get free standardized UI to install the Web Packages in IIS Manager which hopefully will become pretty standard and easy for everyone to understand…  If you do not like to use the UI the package can be installed via commandline as well…:-)
  10. Most of the automated tools (providers) required for packaging  your web application and its dependencies are available out of the box (few of which are IIS Settings, SQL DBs, Web Content, GAC assemblies, COM components, Registry keys etc)… 

Finally let me mention the out of the box providers which can be invoked when you want to package your web application…  You actually have a choice to call any of these providers depending on what parts of your Web Application you like to be packaged… These are my other +20 reasons why you should create a web package…

  1. File System Directory to move a files & folder which contains your web application files like .aspx, .config, images, .js, .css, .master etc – contentPath
  2. Creating a new IIS Web Application for your web– iisApp
  3. Moving IIS7 and above (read Vista, Win2k8, Win7, Win2k8 R2 and above) Configuration Settings associated with your web (e.g. Default Document, ApplicationPool Mapping etc) – appHostConfig
  4. IIS5.1 & 6 (read XP, Win2K3 compatibility)  Metabase Configuration Settings (parallel to IIS7+ settings above) - metakey
  5. Pulling data & schema from existing SQL Server Database or custom generated .SQL files which your web uses– dbfullSQL
  6. Any Security Certificates (e.g. SSL & ClientAuth) that your web depends upon- cert
  7. Any GACed assemblies like 3rd party controls or libraries that your web uses – gacAssembly
  8. Any custom IIS7+ Application Pool that your web has created– appPoolConfig
  9. Registry key associated with your webs – regkey
  10. 32 bit COM Object – comObject32
  11. 64 bit COM Object – comObject64
  12. Security ACLs associated with folder – setAcl
  13. Granular control by pulling just a registry value - regValue
  14. ASP.NET root web configuration file on 32 bit machine – rootWebConfig32
  15. ASP.NET root web configuration file on 64 bit machine – rootWebConfig64
  16. Similar type of support for packaging MySQL DB – dbMySQL
  17. Packaging Machine.Config of 32 bit machine – machineConfig32
  18. Packaging Machine.Config of 64 bit machine – machineConfig64
  19. If there is still a provider missing then you can very easily create one – yourCustomProvider
  20. A secret provider which I am not allowed to talk about just yet :-), but trust me it is really a killer provider - secretProvider

So now that you have 10 +20 reasons to create a web package let us talk about how to create one… From end developer/IT pro standpoint you can create Web Packages from various different avenues, some of which are:

Please follow the links above to create a web package using your preferred method… I hope you are jazzed about being able to archive and deploy your web applications using Web Packaging…

Saturday, May 30, 2009

Database Deployment with Visual Studio 10

Visual Studio 2010 (VS 10) Beta1 was released recently...  You can download VS 10 Beta1 from Microsoft download page….

Do check out the update on Visual Studio features for Web Developers on our team blog…

We have been discussing about a bunch of deployment features previously and today we will discuss about Database Deployment with VS 10….

VS 10 will allow you to deploy your databases both while creating a web package as well as while publishing directly to a web server provided by your hoster…

To catch up on the previous web deployment posts check out the below links:

  • Web Deployment with VS 2010 and IIS
  • Web Packaging: Creating a Web Package using VS 2010
  • Web Packaging: Creating web packages using MSBuild
  • How does Web Deployment with VS 10 & MSDeploy Work?
  • Installing Web Packages using Command Line
  • Web.config Transformation

     

    Apart from the “Package/Publish” tab, with VS10 we will now have a new tab called “Deploy-SQL” in the project properties of Web Application Projects (WAPs)

    The “Deploy SQL” tab looks like below:

    Deploy SQL tab

    Firstly let us note that this tab is Build configuration aware i.e. you can configure different settings for “Release” vs “Debug” environment… I have set the configuration to “Release”  and Platform to “Any CPU” for the above example…

  • TIP:  If you are deploying to a hosted environment then you can create different build configurations per hoster e.g. “DiscountASP” or “OrcsWeb”, this way you can configure various Database deployment settings per hoster…  You can use the same principle for various different database servers you are going to even within your intranet…

    Anyways, the first grid on “Deploy SQL”  tab looks like below and actually is a MASTER part of MASTER-DETAIL view of your Database Deployment Settings.  Every Database Entry in the grid below is a representative of a group of database settings representing source and destination database information:

    connectionString name grid

    i.e. Database Entry (Friendly Name) = Source Database Information + Destination Database Information

    My advice would be to create one entry per every destination database you are deploying to…  The reason why I am emphasizing destination database is coz many folks want to deploy more than one source databases to a single destination database…

    One classic example of this is when you are using ASP.NET membership or login features then ASP.NET automatically creates ASP.NET DB in your project AppData directory, apart from this people also like to create a separate ApplicationDB which has the application specific business data.  As you can imagine this results into two different source DBs.  When you are trying to deploy to a shared hosting environment then many times you are paying per database to your hoster and the obvious thought “my ApplicationDB does not conflict with ASP.NET DB in anyway, I am happy to have both of the DBs to go to the same destination DB without paying for two databases”…  In such a situation you would want to create one database entry in the grid above for every destination connection string that you have.

    The “Add” button at the bottom allows you to add a “Friendly Name” for your Database Entry…  If you would like to go to more than one destination database you can feel free to add as many Database Entries in the grid above as you want… For simplicity of tracking I would recommend using your connectionString name as the Friendly Name in the grid above.

    As you might have already noticed each entry in the grid also has a check box next to it…  The reason why this check box is provided is so that once you configure the database entry then you do not have to completely remove it  by clicking “Remove” button (and loose all the configured data)… If you do not want to include a  particular database Entry (friendly name) in a particular deployment scenario you can simply exclude it by un-checking the checkbox. 

    In order to permanently “Remove” the database entry you can select the entry to be removed and can click the “Remove” button….

  • Let us now take a look at the details of a database entry (e.g details of “productsDB” in the above example).  As I mentioned above the details are going to be broken down into two major categories…

    1. Destination Database Information

    2. Source Database Information

    _____________________________________________________________________________________________________

    Destination Database Information: This section looks as below:

    destination database information

    It is relatively simple, coz all it contains is connection string for the destination database… Typically when you get a hosted account your hoster will send you the connection string of your hosted database in an email.  This connectionString should go into the above text box.

    This field is kept optional and the reason behind it is that if you are using Web Packaging as a model for your deployment and are likely to hand over the web package to your system administrator or someone who will provide connectionString at install time then you can feel free to leave this field empty. 

    Do note that if you are directly publishing to a hoster (i.e. not packaging) and you have left this field empty then you will get an error during publishing.

    __________________________________________________________________________________________________

    Source Database Information: This section looks as below:

    source database information

    The first thing you will see in the Source Database Information is a check box which indicates “Pull data from an existing database” … If you have a local SQL Server database (SQL 2005 or 2008) which you are using for development then this will allow you to extract your database to deploy to the destination database (mentioned in the section above)….

    The first setting under “Pull data from an existing database” is Connection string for the source database… This text box is enabled only when you check the check box for “Pull data from…”  You can also click the “…” button next to the connection string text box which will launch the connection String builder dialog as below:

    connectionString Builder

    This dialog can help you easily create the connection String for your local database…

    The next set of controls under the source connection String text box allow you to determine what kind of SQL Script would like to generate from your source database.  Currently there are two options available…

    Schema Only  - Choosing this will only script the schema of your source database

    Complete Database – Choosing this will script both schema and data of your source database

    On your dev SQL Server it is likely that you might have some test data, in that situation you would want to choose “Schema Only” option which will only pick up the DB schema leaving out the data…  On the other hand if you choose complete database everything from your source database will be scripted…

    Insider Note:  VS 10 Database Deployment is using SQL Management Objects (SMO) behind the scenes to script your database…  SMO is a tried and tested API for scripting huge databases… scriptSchema & scriptData are SMO scripting options which Visual Studio is setting when you choose one of the options above…

    The next check box is “Exclude object with no schema information” which will give you further fine grain control on scripting your database.  If you do not care about schemaQualify feel free to uncheck this checkbox…

    Database Source Scripts -  You might have noticed that in this section there is already an entry called “[Auto-generated Schema Only]”… This entry is added to the source database scripts as soon as you check the “Pull data from an existing database”… At the bottom of Database Source Scripts grid you will notice “Add Script” and “Remove Script” button…  These buttons will allow you to add & remove extra .SQL scripts as your source…

    Most of the times developers or DBAs create .SQL scripts to deploy databases…  These custom .SQL scripts can be added and ordered in the grid (and thereby during deployment) using the up and down arrows…  The “[Auto-generated Schema Only]” is a representative of the script that VS will automatically generate from your source database, it is added to the grid so that you can order it up and down along with the rest of the .SQL scripts that you might want to add…

    Also note that if you are generating your .SQL scripts via tools like Visual Studio Database Edition (Data Dude) or Red Gate then you can add those scripts here to be included in your web package as well. 

    NOTE: There is a way to set up automated build and deployment environment in which you can collect .SQL scripts from Data Dude or Red Gate and provide to VS 10 during web deployment.  I will cover this topic separately in a different blog post…

    _________________________________________________________________________________

    The last section of the “Deploy SQL” tab is a place for you to provide Database Deployment notes so that you can note specific steps you took or scripts you used while deploying databases; this is purely for your reference purposes…. The deployment notes section looks as below…

    Database Deployment Notes

    Once you have provided all of this information you are good to deploy your databases using Visual Studio 2010 Web Deployment…

    Web Packaging  + DB Deployment

    After setting up your DB deployment as shown above you can now right click on your project and hit Package –> Create Package as shown below…Create Package

    The package created as a result will contain your database…  You can read details about creating and installing the web packages below:

  • Web Packaging: Creating a Web Package using VS 2010
  • Web Packaging: Creating web packages using MSBuild
  • Installing Web Packages using Command Line
  •  

    Web Publishing + DB Deployment

    Once you set up the DB then not only will it get included in Web Packages but will also be available to be deployed via Publishing…  You can publish you project by right clicking on your project and hit Publish as shown below…

     Publish

    I will soon write a detailed post on how to use the new “Publishing” features of Visual Studio 2010…

    Hope this information was useful…

    -Vishal

    Tuesday, March 24, 2009

    How to transfer your DB using MSDeploy command Line

    Problem Statement: Lets say you have a database on a server which is live, and you think that there is some problem on the server that you would like to troubleshoot…  You typically want to move your database to your Dev DB box and troubleshoot it there instead of troubleshooting a live server…

    MSDeploy Solution:  MSDeploy can help you achieve this in very simple steps below:

    Learn more about how MsDeploy works

    Step 1: Download MSDeploy and install it on source as well as target machines

    At MIX 2009 we released MSDeploy RC and it is available for free download below:

    You can just download the exe and install standard installation, that should work…

    Step 2:  Create a source manifest for your source machine DB

    Source manifest should look as below:

    <sitemanifest>

    <dbFullSql path=" Data Source=VIJOSHI-DEMO;Initial Catalog=Delete;Integrated Security=True" ScriptSchema=True ScriptData=False />

    </sitemanifest>

    You can save this xml at any location you like… In my case I will save it at C:\Users\vijoshi\Desktop\DBManifest.xml

    The highlighted syntax are scripting options provided by SQL Management Objects… There are more scripting options like TargetServerVersion  which indicates the destination SQL Server version for which you want to generate SQL Scripts…

    ScriptSchema option above will allow you to take the schema of the database (typically you will want this most of the time)

    ScriptData option will allow you to take the data from the DB as well, in our problem statement above you do need the data as well but normally this is a very resource costly option and also might be restricted due to confidentiality policies around data.

    Step 3: Open MSDeploy command prompt

    Start –> All Programs –> IIS Extensions –> MSDeploy Command Console

    check the figure below:

    msdeploy command console

    Step 4:  Run package command to create a .zip file which will contain your .sql scripts

    Call MSDeploy command with below details:

    • verb:sync – This instructs msdeploy to create an action of syncing and as we want to sync our DB that is the verb we will choose…
    • source:manifest – This will tell msdeploy what to use as a source…  In our case we have created a manifest file in Step 2 which is our source (note that for MSDeploy the xml is the source, which inturn calls db as the source)
    • dest:Package -   This will tell msdeploy to create a package of the source.  In our case the DB will be scripted into .sql file and will be put into .zip package.

    The command that you will use on command line will be as below:

    C:\Program Files\IIS\Microsoft Web Deploy>msdeploy -verb:sync -source:manifest=C:\Users\vijoshi\Desktop\DBManifest.xml -dest:Packa
    ge=C:\Users\vijoshi\Desktop\DBPackage.zip

    The output of this command should show something like below:

    db packaging commandline

    Step 5:  Transport your .zip package to the destination

    Now you can simply copy the .zip file to your target machine and if you just need the .sql file to use SQL Management studio to install it then just open the .zip file in windows explorer and you should have the .sql file in there… 

    Alternatively if you want to use MSDeploy itself to recreate the DB on the destination then it is equally easy as well…

    Step 6: Run MSdeploy command to unzip the packaged DB

    This time the zip file is the source and we want to put the DB into different DB, I will call it “TargetDB”…

    For that I will create destination manifest similar to the source manifest I created in Step 2… My destination manifest will look as below:

    <sitemanifest>

    <dbFullSql path=" Data Source=VIJOSHI-DEMO;Initial Catalog=TargetDB;Integrated Security=True"/>

    </sitemanifest>


    Few things to note:

    • My connection string has to change on the destination to match the destination credentials
    • I do not need SMO options now as I am no more scripting anything rather I am just deploying the already scripted objects
    • I will save this file as C:\Users\vijoshi\Desktop\DBDestinationManifest.xml

    Again on MSDeploy command prompt I can provide below MSDeploy command

    C:\Program Files\IIS\Microsoft Web Deploy>msdeploy -verb:sync -source:package=C:\Users\vijoshi\desktop\DBPackage.zip -dest:manifes
    t=C:\Users\vijoshi\Desktop\DBDestinationManifest.xml

    After running the command you should have your DB updated on your local box as below:

    transferred DB

    Hope this helps!!

    -Vishal