Simple Deployment


If deployment is part of an application's original design considerations, deployment can be as simple as copying a set of files to the target computer. For a Web application, it can be a simple menu choice in Visual Studio 2005. This section discusses these simple deployment scenarios.

To see how the various deployment options are set up, you must have an application to deploy. The sample download at www.wrox.com contains three projects: SampleClientApp, SampleWebApp, and AppSupport. SampleClientApp is a smart client application. SampleWebApp is a simple Web app. AppSupport is a class library that contains one simple class that returns a string with the current date and time. SampleClientApp and SampleWebApp use AppSupport to fill a label with the output of AppSupport. To use the examples, first load and build AppSupport. Then, in each of the other applications, set a reference to the newly built AppSupport dll.

Here is the code for the AppSupport assembly:

 using System; namespace AppSupport { /// <summary> /// Simple assembly to return date and time string. /// </summary> public class Support { private Support() { } public static string GetDateTimeInfo() { DateTime dt = DateTime.Now; return string.Concat(dt.ToLongDateString(), " ", dt.ToLongTimeString()); } } } 

This simple assembly suffices to demonstrate the deployment options available to you.

Xcopy

Xcopy deployment is a term used for the process of copying a set of files to a folder on the target machine and then executing the application on the client. The term comes from the DOS command xcopy.exe. Regardless of the number of assemblies, if the files are copied into the same folder, the application will execute — rendering the task of editing the configuration settings or registry obsolete.

To see how an xcopy deployment works, open the SampleClientApp solution (SampleClientApp.sln) that is part of the sample download file. Change the target to Release and do a full compile. Next, use either My Computer or File Explorer to navigate to the project folder\SampleClientApp\ bin\ Release and double-click SampleClientApp.exe to run the application. Now click the button to open another dialog. This verifies that the application functions properly. Of course this folder is where Visual Studio placed the output, so you would expect the application to work.

Create a new folder and call it ClientAppTest. Copy the two files from the release folder to this new folder and then delete the release folder. Again, double-click the SampleClientApp.exe file to verify that it's working.

That's all there is to it; xcopy deployment provides the ability to deploy a fully functional application simply by copying the assemblies to the target machine. Just because the example that is used here is simple does not mean that this process cannot work for more complex applications. There really is no limit to the size or number of assemblies that can be deployed using this method. The reason that you might not want to use xcopy deployment is the ability to place assemblies in the Global Assembly Cache (GAC) or the ability to add icons to the Start Menu. Also, if your application still relies on a COM library of some type, you will not be able to register the COM components easily.

Xcopy and Web Applications

Xcopy deployment can also work with Web applications with the exception of the folder structure. You must establish the virtual directory of your Web application and configure the proper user rights. This process is generally accomplished with the IIS administration tool. After the virtual directory is set up, the Web application files can be copied to the virtual directory. Copying a Web application's files can be a bit tricky. A couple of configuration files need to be as accounted for as well as the images that the pages might be using.

Copy Web Tool

A better way would be to use the Copy Web tool. The Copy Web tool is accessed from the Website Copy Web Site menu choice in Visual Studio 2005. It is basically an FTP client for transferring files to and from a remote location. The remote location can be any FTP or Web site including local Web sites, IIS Web sites and Remote (Frontpage) Web sites. Another feature of the Copy Web tool is that it will synchronize files on the remote server with the source site. The source site will always be the site that is currently open in Visual Studio 2005. If the current project has multiple developers this tool can be used to keep changes in sync with the local development site. Changes can be synced back with a common server for testing.

Publishing a Web Site

Another deployment option for Web projects is to publish the Web site. Publishing a Web site will pre- compile the entire site and place the compiled version into a specified location. The location can be a file share, FTP location, or any other location that can be accessed via HTTP. The compilation process strips all source code from the assemblies and creates the dlls for deployment. This also includes the mark-up contained in the .ASPX source files. Instead of containing the normal mark-up, the .ASPX files contain a pointer to an assembly. Each .ASPX file relates to an assembly. This process works regardless of the model, code behind or single file.

The advantages of publishing a Web site are speed and security. Speed is enhanced because all of the assemblies are already compiled. Otherwise, the first time a page is accessed there is a delay while the page and dependent code is compiled and cached. The security is enhanced because the source code is not deployed. Also, because everything is pre-compiled before deployment all compilation errors will be found.

You publish a Web site from the Website Publish Web Site menu choice. You need to supply the location to publish to. Again, this can be a file share, FTP location, Web site, or local disk path. After the compilation is finished, the files are placed in the specified location. From there they can be copied to a staging server, test server, or the production server.




Professional C# 2005
Pro Visual C++ 2005 for C# Developers
ISBN: 1590596080
EAN: 2147483647
Year: 2005
Pages: 351
Authors: Dean C. Wills

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net