Deployment


In this section, we will take a brief look at how you can deploy your server controls and components for use by page developers. ASP.NET Web applications use the same assembly deployment model available to all .NET applications. This model defines two types of assemblies that are based on their deployment mode: private assemblies and shared assemblies .

Private assemblies are deployed by being placed into the private bin directory of an application. For ASP.NET Web applications, this private bin directory exists directly under the virtual root associated with the Web application. For example, the sample pages in this code are in the BookWeb application or virtual root. If this application is rooted at C:\Inetpub\wwwroot\BookWeb, its associated bin directory is C:\Inetpub\ wwwroot \BookWeb\bin. Because the MSPress.ServerControls.dll assembly that contains the samples you have seen in this book is placed in this directory, it is considered a private assembly. A private assembly must be copied into the private bin directory of each application that needs to use it. A private assembly can be referred to by only its name ”for example, MSPress.ServerControls .

As the name suggests, shared assemblies are shared by multiple applications. Shared assemblies are deployed into the global assembly cache , also known as the GAC . If you create components that are intended for use by multiple applications, you might consider installation into the GAC. The GAC can also contain multiple versions of your assembly at once. This allows you to deploy a newer version of your component without the risk of inadvertently breaking an existing application that depends on specific behavior of your older implementation. As a result, the GAC must be able to uniquely identify each assembly it contains. This is accomplished by referring to each assembly with its full name, which consists of its name, version, culture, and public key token. For example, the full name of the System.Web assembly that contains the implementation of ASP.NET is "System.Web, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f 11d50a3a."

Assemblies with this four-part name are often referred to as strongly named assemblies . The name, version, and culture are specified by using metadata attributes applied to the assembly, and the public key token is derived from the public key of the public/private key pair used to sign the assembly. By convention, assembly-level attributes are specified in an AssemblyInfo.cs file. Listing 17-17 lists relevant portions of the AssemblyInfo.cs file that is compiled into the MSPress.ServerControls assembly.

Listing 17-17 Assembly attributes in AssemblyInfo.cs that contribute to the assembly name
 usingSystem; usingSystem.Reflection; [assembly:AssemblyTitle("MSPress.ServerControls")] [assembly:AssemblyCulture("")] [assembly:AssemblyVersion("1.0.0.0")] 

To complete the process of generating a strongly named assembly, you need to sign the assembly with a public/private key pair. A test key pair can be generated by using the sn.exe tool that is included in the .NET Framework SDK by using this command:

 snkMSPress.ServerControls.snk 

The key pair can be included into the compile process by using the AssemblyKeyFileAttribute metadata attribute. AssemblyKeyFileAttribute can be added to AssemblyInfo.cs as follows :

 [assembly:AssemblyKeyFile("MSPress.ServerControls.snk")] 

Once you have a signed assembly, you can install it into the GAC by using another tool that ships with the .NET Framework SDK, gacutil.exe. To do so, use this command:

 gacutil/iMSPress.ServerControls.dll 

The signing process can also be delayed and performed outside your main compile process. Delay signing is described in more detail in the .NET Framework SDK documentation.

Note

When you create a new project in Visual Studio .NET, the project contains an AssemblyInfo.cs file that contains an assembly attribute defining its version as "1.0.*". The asterisk (*) is substituted with a version number that is incremented each time you build your assembly. You should never rely on this auto-increment functionality because it has the side effect of breaking everything else that depends on version numbers . Instead, you should fix all four parts of the version number and choose something along the lines of "1.0.0.0" before continuing with your development.




Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

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