The Visual Studio 2005 IDE provides us some useful ways to deploy our web sites on a Web Server (IIS). Most of the time, we are going to deploy
our application by creating a Virtual Directory on IIS and this is the best way to deploy it. But sometimes we need to deploy our applications
directly from VS. Visual Studio includes features that integrate with IIS and allows us to create Virtual Directories within the Visual Studio IDE.
Visual Studio provides three important features to deploy our websites:
- Creating a virtual directory at the time of creating a new web project
- Using the Copy Web tool
- Publishing a web site
Creating a virtual directory at the time of creating a new web project
From Visual Studio, when we create a web site, simultaneously create a virtual directory for that web site. In the general case, we create a web site
in our local system and Visual Studio uses its own built-in web server to run that application. But if we want do so, Visual Studio won't use its
built-in web server to deploy the sites, rather a request will be sent to IIS and then IIS will take care of it. Now let us see how to do do this.
- Visual Studio > File > New Web Site.
In that screen, select HTTP in the Location field instead of File System (default). Now provide the URL for that application, as given in the picture.
Visual Studio will create a Virtual Directory on IIS with the named "mydemosites". If that Virtual Directory already exists, it will not create it,
it will just use the existing one.
- Click on OK. Check the Solution path. It will be in localhost.
Visual Studio does has limited functionality of IIS Manager. We can create a Virtual Directory with an existing application.
- Click on Browse button of New Window [shown in the first image].
- Select Default Web Sites.
- Click on Create Virtual Directory, give an alias name and folder path.
This approach has certain limitations:
- If development and production environment are same then all the changes in your application directly affects the live environment, which is not at all preferable.
- The Virtual Directory will be created at the start of your application. We don't have any option to create a virtual directory that way for an existing application.
- Application location should be C:/inetpub/wwwroot, which is some times not preferable to manage other resources of your application.
- We can't configure other settings like Authentication settings, default pages, custom errors, etc.
Using the Copy Web tool
Visual Studio provides a useful tool to transfer our web application files directly from Visual Studio.
- Your Web Site > right click > copy Web Site.
- Click on Copy Web Site... The following screen will appear.
In the Copy Web tool, there are two windows: current location, which is our local solution file, and a remote site that is our target location.
First of all, we have to set the target server to enable the area. For that, we need to click on Connect.
Now, a new window will appaer, using which we can specify the location for the remote web site.
- File System: Remote location will be the local system or a network folder, it will just create a new folder to store the application.
- Local IIS: Create a Virtual Directory on IIS under default web sites. We can also create a new virtual directory as shown earlier.
- FTP site: It is used for the FTP site, we need to configure FTP for that.
- Remote Site: We have to specify the remote site URL for copying the files.
After we specify the location, we will have the enabled remote server section and enabled button to copy files.
Publishing a web site
This feature helps us to deploy our application to a production server and keep the source code secure. Visual Studio Publishing Features use
the aspnet_complier command line utility to secure our code. It will just publish the site after compiling the code. We just need to deploy it on IIS server. There are only a few steps.
- Right click on Web Site > Publish Web Site.
- Set the location for your publishing, you can directly deploy to IIS or set location as already discussed. Check 'Allow this precompiled site to be updateable'.
This will help you to change code on your live site without recompiling. E.g., suppose you need to change an alert message, just change
the client code and it will be reflected on the live site, and you do not need to recompile.
These are the three approaches provided by VS2005. Hope you enjoyed the article.
- Written on Sunday, Octbor 19, 2008.