Archive for January, 2008

Web design careers - CHAPTER 2 BUILDING C# APPLICATIONS 39 When

Thursday, January 31st, 2008

CHAPTER 2 BUILDING C# APPLICATIONS 39 When you run the program again, the output is identical. The only difference between the two applications is the fact that the current logic has been split among multiple files. Referencing Multiple External Assemblies On a related note, what if you need to reference numerous external assemblies using csc.exe? Simply list each assembly using a semicolon-delimited list. You don t need to specify multiple external assemblies for the current example, but some sample usage follows: csc /r:System.Windows.Forms.dll;System.Drawing.dll *.cs Working with csc.exe Response Files As you might guess, if you were to build a complex C# application at the command prompt, your life would be full of pain as you type in the flags that specify numerous referenced assemblies and *.cs input files. To help lessen your typing burden, the C# compiler honors the use of response files. C# response files contain all the instructions to be used during the compilation of your current build. By convention, these files end in a *.rsp (response) extension. Assume that you have created a response file named TestApp.rsp that contains the following arguments (as you can see, comments are denoted with the # character): # This is the response file # for the TestApp.exe app # of Chapter 2. # External assembly references. /r:System.Windows.Forms.dll # output and files to compile (using wildcard syntax). /target:exe /out:TestApp.exe *.cs Now, assuming this file is saved in the same directory as the C# source code files to be compiled, you are able to build your entire application as follows (note the use of the @ symbol): csc @TestApp.rsp If the need should arise, you are also able to specify multiple *.rsp files as input (e.g., csc @FirstFile.rsp @SecondFile.rsp @ThirdFile.rsp). If you take this approach, do be aware that the compiler processes the command options as they are encountered! Therefore, command-line arguments in a later *.rsp file can override options in a previous response file. Also note that flags listed explicitly on the command line before a response file will be overridden by the specified *.rsp file. Thus, if you were to enter csc /out:MyCoolApp.exe @TestApp.rsp the name of the assembly would still be TestApp.exe (rather than MyCoolApp.exe), given the /out:TestApp.exe flag listed in the TestApp.rsp response file. However, if you list flags after a response file, the flag will override settings in the response file. Thus, in the following command set, your assembly is indeed named MyCoolApp.exe. csc @TestApp.rsp /out:MyCoolApp.exe Note The /reference flag is cumulative. Regardless of where you specify external assemblies (before, after, or within a response file) the end result is a summation of each reference assembly.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Figure 2-2. (Apache web server) Your first Windows Forms application Compiling

Wednesday, January 30th, 2008

Figure 2-2. Your first Windows Forms application Compiling Multiple Source Files with csc.exe The current incarnation of the TestApp.exe application was created using a single *.cs source code file. While it is perfectly permissible to have all of your .NET types defined in a single *.cs file, most projects are composed of multiple *.cs files to keep your code base a bit more flexible. Assume you have authored an additional class contained in a new file named HelloMsg.cs: // The HelloMessage class using System; using System.Windows.Forms; class HelloMessage { public void Speak() { MessageBox.Show(”Hello…”); } } Now, update your initial TestApp class to make use of this new type, and comment out the previous Windows Forms logic: using System; // Don’t need this anymore. // using System.Windows.Forms; class TestApp { public static void Main() { Console.WriteLine(”Testing! 1, 2, 3″); // Don’t need this anymore either. // MessageBox.Show(”Hello…”); // Exercise the HelloMessage class! HelloMessage h = new HelloMessage(); h.Speak(); } } You can compile your C# files by listing each input file explicitly: csc /r:System.Windows.Forms.dll testapp.cs hellomsg.cs As an alternative, the C# compiler allows you to make use of the wildcard character (*) to inform csc.exe to include all *.cs files contained in the project directory as part of the current build: csc /r:System.Windows.Forms.dll *.cs CHAPTER 2 38 BUILDING C# APPLICATIONS
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

CHAPTER 2 BUILDING C# APPLICATIONS 37 Figure (Web host server)

Tuesday, January 29th, 2008

CHAPTER 2 BUILDING C# APPLICATIONS 37 Figure 2-1. TestApp in action TestApp.exe can now be run from the command line (see Figure 2-1). Referencing External Assemblies Next up, let s examine how to compile an application that makes use of types defined in a separate .NET assembly. Speaking of which, just in case you are wondering how the C# compiler understood your reference to the System.Console type, recall from Chapter 1 that mscorlib.dll is automatically referenced during the compilation process (if for some strange reason you wish to disable this behavior, you may specify the /nostdlib flag). To illustrate the process of referencing external assemblies, let s update the TestApp application to display aWindows Forms message box. Open your TestApp.cs file and modify it as follows: using System; // Add this! using System.Windows.Forms; class TestApp { public static void Main() { Console.WriteLine(”Testing! 1, 2, 3″); // Add this! MessageBox.Show(”Hello…”); } } Notice the reference to the System.Windows.Forms namespace via the C# using keyword (introduced in Chapter 1). Recall that when you explicitly list the namespaces used within a given *.cs file, you avoid the need to make use of fully qualified names (which can lead to hand cramps). At the command line, you must inform csc.exe which assembly contains the used namespaces. Given that you have made use of the MessageBox class, you must specify the System.Windows. Forms.dll assembly using the /reference flag (which can be abbreviated to /r): csc /r:System.Windows.Forms.dll testapp.cs If you now rerun your application, you should see what appears in Figure 2-2 in addition to the console output.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Web hosting services - CHAPTER 2 36 BUILDING C# APPLICATIONS Building

Monday, January 28th, 2008

CHAPTER 2 36 BUILDING C# APPLICATIONS Building C# Applications Using csc.exe Now that your development machine recognizes csc.exe, the next goal is to build a simple single file assembly named TestApp.exe using the C# command-line compiler and Notepad. First, you need some source code. Open Notepad and enter the following: // A simple C# application. using System; class TestApp { public static void Main() { Console.WriteLine(”Testing! 1, 2, 3″); } } Once you have finished, save the file in a convenient location (e.g., C:CscExample) as TestApp.cs. Now, let s get to know the core options of the C# compiler. The first point of interest is to understand how to specify the name and type of assembly to create (e.g., a console application named MyShell.exe, a code library named MathLib.dll, aWindows Forms application named MyWinApp.exe, and so forth). Each possibility is represented by a specific flag passed into csc.exe as a command-line parameter (see Table 2-2). Table 2-2. Output-centric Options of the C# Compiler Option Meaning in Life /out This option is used to specify the name of the assembly to be created. By default, the assembly name is the same as the name of the initial input *.cs file (in the case of a *.dll) or the name of the type containing the program s Main() method (in the case of an *.exe). /target:exe This option builds an executable console application. This is the default file output type, and thus may be omitted when building this application type. /target:library This option builds a single-file *.dll assembly. /target:module This option builds a module. Modules are elements of multifile assemblies (fully described in Chapter 11). /target:winexe Although you are free to build Windows-based applications using the /target:exe flag, the /target:winexe flag prevents a console window from appearing in the background. To compile TestApp.cs into a console application named TextApp.exe, change to the directory containing your source code file and enter the following command set (note that command-line flags must come before the name of the input files, not after): csc /target:exe TestApp.cs Here I did not explicitly specify an /out flag, therefore the executable will be named TestApp.exe, given that TestApp is the class defining the program s entry point (the Main() method). Also be aware that most of the C# compiler flags support an abbreviated version, such as /t rather than /target (you can view all abbreviations by entering csc /? at the command prompt): csc /t:exe TestApp.cs Furthermore, given that the /t:exe flag is the default output used by the C# compiler, you could also compile TestApp.cs simply by typing csc TestApp.cs
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Web host server - CHAPTER 2 BUILDING C# APPLICATIONS 35 To

Sunday, January 27th, 2008

CHAPTER 2 BUILDING C# APPLICATIONS 35 To equip your development machine to compile *.cs files from any directory, follow these steps (which assume aWindows XP installation; Windows NT/2000 steps will differ slightly): 1. Right-click the My Computer icon and select Properties from the pop-up menu. 2. Select the Advanced tab and click the Environment Variables button. 3. Double-click the Path variable from the System Variables list box. 4. Add the following line to the end of the current Path value (note each value in the Path variable is separated by a semicolon): C:WindowsMicrosoft.NETFrameworkv2.0.50215 Of course, your entry may need to be adjusted based on your current version and location of the .NET Framework 2.0 SDK (so be sure to do a sanity check using Windows Explorer). Once you have updated the Path variable, you may take a test run by closing any command windows open in the background (to commit the settings), and then opening a new command window and entering csc /? If you set things up correctly, you should see a list of options supported by the C# compiler. Note When specifying command-line arguments for a given .NET development tool, you may use either a or / (e.g., csc -? or csc /?). Configuring Additional .NET Command-Line Tools Before you begin to investigate csc.exe, add the following additional Path variable to the System Variables list box (again, perform a sanity check to ensure a valid directory): C:Program FilesMicrosoft Visual Studio 8SDKv2.0Bin Recall that this directory contains additional command-line tools that are commonly used during .NET development. With these two paths established, you should now be able to run any .NET utility from any command window. If you wish to confirm this new setting, close any open command windows, open a new command window, and enter the following command to view the options of the GAC utility, gacutil.exe: gacutil /? Tip Now that you have seen how to manually configure your machine, I ll let you in on a shortcut. The .NET Framework 2.0 SDK provides a preconfigured command window that recognizes all .NET command-line utilities out of the box. Using the Start button, activate the SDK Command Prompt located under the All Programs .Microsoft .NET Framework SDK v2.0 menu selection.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

CHAPTER 2 34 BUILDING C# APPLICATIONS Table (Free web servers)

Saturday, January 26th, 2008

CHAPTER 2 34 BUILDING C# APPLICATIONS Table 2-1. Subdirectories of the .NET Framework 2.0 SDK Installation Root Subdirectory Meaning in Life Bin Contains amajority of the .NET development tools. Check out StartTools.htm for a description of each utility. Bootstrapper Although you can ignore most of the content in the directory, be aware that dotnetfx.exe (see Chapter 1) resides under the PackagesDotNetFx subdirectory. CompactFramework Contains the installer program for the .NET Compact Framework 2.0. Samples Provides the setup program (and core content) for the .NET Framework 2.0 SDK samples. To learn how to install the samples, consult StartSamples.htm. In addition to the content installed under C:Program FilesMicrosoft Visual Studio 8SDKv2.0, the setup program also creates the Microsoft.NETFramework subdirectory under your Windows directory. Here you will find a subdirectory for each version of the .NET Framework installed on your machine. Within a version-specific subdirectory, you will find command-line compilers for each language that ships with the Microsoft .NET Framework (CIL, C#, Visual Basic .NET, J#, and JScript .NET), as well as additional command-line development utilities and .NET assemblies. The C# Command-Line Compiler (csc.exe) There are a number of techniques you may use to compile C# source code. In addition to Visual Studio 2005 (as well as various third-party .NET IDEs), you are able to create .NET assemblies using the C# command-line compiler, csc.exe (where csc stands for C-Sharp Compiler). This tool is included with the .NET Framework 2.0 SDK. While it is true that you may never decide to build a large-scale application using the command-line compiler, it is important to understand the basics of how to compile your *.cs files by hand. I can think of a few reasons you should get a grip on the process: The most obvious reason is the simple fact that you might not have a copy of Visual Studio 2005. You plan to make use of automated build tools such as MSBuild or NAnt. You want to deepen your understanding of C#. When you use graphical IDEs to build applications, you are ultimately instructing csc.exe how to manipulate your C# input files. In this light, it s edifying to see what takes place behind the scenes. Another nice by-product of working with csc.exe in the raw is that you become that much more comfortable manipulating other command-line tools included with the .NET Framework 2.0 SDK. As you will see throughout this book, a number of important utilities are accessible only from the command line. Configuring the C# Command-Line Compiler Before you can begin to make use of the C# command-line compiler, you need to ensure that your development machine recognizes the existence of csc.exe. If your machine is not configured correctly, you are forced to specify the full path to the directory containing csc.exe before you can compile your C# files.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Building C# Applications (Msn web hosting) As a C# programmer, you

Friday, January 25th, 2008

Building C# Applications As a C# programmer, you may choose among numerous tools to build .NET applications. The point of this chapter is to provide a tour of various .NET development options, including, of course, Visual Studio 2005. The chapter opens, however, with an examination of working with the C# command-line compiler, csc.exe, and the simplest of all text editors, Notepad (notepad.exe). Along the way, you will also learn about the process of debugging .NET assemblies at the command line using cordbg.exe. Once you become comfortable compiling and debugging assemblies IDE-free, you will then examine how the TextPad application allows you to edit and compile C# source code files in a (slightly) more sophisticated manner. While you could work through this entire text using nothing other than csc.exe and Notepad/ TextPad, I d bet you are also interested in working with feature-rich integrated development environments (IDEs). To this end, you will be introduced to an open source IDE named SharpDevelop. This IDE rivals the functionality of many commercial .NET development environments (and it s free!). After briefly examining the Visual C# 2005 Express IDE, you will turn your attention to Visual Studio 2005. This chapter wraps up with a quick tour of a number of complementary .NET development tools (many of which are open source) and describes where to obtain them. Installing the .NET Framework 2.0 SDK Before you are able to build .NET applications using the C# programming language and the .NET Framework, the first step is to install the freely downloadable .NET Framework 2.0 Software Development Kit (SDK). Do be aware that the .NET Framework 2.0 SDK is automatically installed with Visual Studio 2005 as well as Visual C# 2005 Express; therefore, if you plan to use either of these IDEs, there is no need to manually download or install this software package. If you are not developing with Visual Studio 2005/Visual C# 2005 Express, navigate to http://msdn.microsoft.com/netframework and search for .NET Framework 2.0 SDK . Once you have located the appropriate page, download setup.exe and save it to a location on your hard drive. At this point, double-click the executable to install the software. After the installation process has completed, your development machine will not only be configured with the necessary .NET infrastructure, but also now contain numerous development tools, a very robust help system, sample code, and tutorials, as well as various white papers. By default, the .NET Framework 2.0 SDK is installed under C:Program FilesMicrosoft Visual Studio 8SDKv2.0. Here you will find StartHere.htm, which (as the name suggests) serves as an entry point to other related documentation. Table 2-1 describes the details behind some of the core subdirectories off the installation root. 33 C H A P T E R 2
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Com web hosting - CHAPTER 1 THE PHILOSOPHY OF .NET 31

Thursday, January 24th, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 31 Summary The point of this chapter was to lay out the conceptual framework necessary for the remainder of this book. I began by examining a number of limitations and complexities found within the technologies prior to .NET, and followed up with an overview of how .NET and C# attempt to simplify the current state of affairs. .NET basically boils down to a runtime execution engine (mscoree.dll) and base class library (mscorlib.dll and associates). The common language runtime (CLR) is able to host any .NET binary (aka assembly) that abides by the rules of managed code. As you have seen, assemblies contain CIL instructions (in addition to type metadata and the assembly manifest) that are compiled to platformspecific instructions using a just-in-time (JIT) compiler. In addition, you explored the role of the Common Language Specification (CLS) and Common Type System (CTS). This was followed by an examination of the ildasm.exe utility, as well as coverage of how to configure a machine to host .NET applications using dotnetfx.exe. I wrapped up by briefly addressing the platform-independent nature of C# and the .NET platform.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

30 CHAPTER 1 THE PHILOSOPHY OF (Web host sites) .NET

Wednesday, January 23rd, 2008

30 CHAPTER 1 THE PHILOSOPHY OF .NET Table 1-5. Partitions of the CLI Partitions of ECMA-335 Meaning in Life Partition I: Architecture Describes the overall architecture of the CLI, including the rules of the CTS and CLS, and the mechanics of the .NET runtime engine Partition II: Metadata Describes the details of .NET metadata Partition III: CIL Describes the syntax and semantics of CIL code Partition IV: Libraries Gives a high-level overview of the minimal and complete class libraries that must be supported by a .NET distribution. Partition V: Annexes A collection of odds and ends details such as class library design guidelines and the implementation details of a CIL compiler Be aware that Partition IV (Libraries) defines only a minimal set of namespaces that represent the core services expected by a CLI distribution (collections, console I/O, file I/O, threading, reflection, network access, core security needs, XML manipulation, and so forth). The CLI does not define namespaces that facilitate web development (ASP.NET), database access (ADO.NET), or desktop graphical user interface (GUI) application development (Windows Forms). The good news, however, is that the mainstream .NET distributions extend the CLI libraries with Microsoft-compatible equivalents of ASP.NET, ADO.NET, and Windows Forms in order to provide fullfeatured, production-level development platforms. To date, there are two major implementations of the CLI (beyond Microsoft s Windows-specific offering). Although this text focuses on the creation of .NET applications using Microsoft s .NET distribution, Table 1-6 provides information regarding the Mono and Portable .NET projects. Table 1-6. Open Source .NET Distributions Distribution Meaning in Life http://www.mono-project.com The Mono project is an open source distribution of the CLI that targets various Linux distributions (e.g., SuSE, Fedora, and so on) as well as Win32 and Mac OS X. http://www.dotgnu.org Portable.NET is another open source distribution of the CLI that runs on numerous operating systems. Portable.NET aims to target as many operating systems as possible (Win32, AIX, BeOS, Mac OS X, Solaris, all major Linux distributions, and so on). Both Mono and Portable.NET provide an ECMA-compliant C# compiler, .NET runtime engine, code samples, documentation, as well as numerous development tools that are functionally equivalent to the tools that ship with Microsoft s .NET Framework 2.0 SDK. Furthermore, Mono and Portable.NET collectively ship with a VB .NET, Java, and C complier. Note If you wish to learn more about Mono or Portable.NET, check out Cross-Platform .NET Development: Using Mono, Portable.NET, and Microsoft .NET by M. J. Easton and Jason King (Apress, 2004).
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

CHAPTER 1 THE PHILOSOPHY OF .NET 29 (Cpanel web hosting)

Wednesday, January 23rd, 2008

CHAPTER 1 THE PHILOSOPHY OF .NET 29 To be sure, ildasm.exe has more options than shown here, and I will illustrate additional features of the tool where appropriate in the text. As you read through this text, I strongly encourage you to open your assemblies using ildasm.exe to see how your C# code is processed into platform-agnostic CIL code. Although you do not need to become an expert in CIL code to be a C# superstar, understanding the syntax of CIL will only strengthen your programming muscle. Deploying the .NET Runtime It should come as no surprise that .NET assemblies can be executed only on a machine that has the .NET Framework installed. As an individual who builds .NET software, this should never be an issue, as your development machine will be properly configured at the time you install the freely available .NET Framework 2.0 SDK (as well as commercial .NET development environments such as Visual Studio 2005). However, if you deploy an assembly to a computer that does not have .NET installed, it will fail to run. For this reason, Microsoft provides a setup package named dotnetfx.exe that can be freely shipped and installed along with your custom software. This installation program is included with the .NET Framework 2.0 SDK, and it is also freely downloadable from Microsoft. Once dotnetfx.exe is installed, the target machine will now contain the .NET base class libraries, .NET runtime (mscoree.dll), and additional .NET infrastructure (such as the GAC). Note Do be aware that if you are building a .NET web application, the end user s machine does not need to be configured with the .NET Framework, as the browser will simply receive generic HTML and possibly client-side JavaScript. The Platform-Independent Nature of .NET To close this chapter, allow me to briefly comment on the platform-independent nature of the .NET platform. To the surprise of most developers, .NET assemblies can be developed and executed on non-Microsoft operating systems (Mac OS X, numerous Linux distributions, BeOS, and FreeBSD, to name a few). To understand how this is possible, you need to come to terms to yet another abbreviation in the .NET universe: CLI (Common Language Infrastructure). When Microsoft released the C# programming language and the .NET platform, it also crafted a set of formal documents that described the syntax and semantics of the C# and CIL languages, the .NET assembly format, core .NET namespaces, and the mechanics of a hypothetical .NET runtime engine (known as the Virtual Execution System, or VES). Better yet, these documents have been submitted to Ecma International as official international standards (http://www.ecma-international.org). The specifications of interest are ECMA-334: The C# Language Specification ECMA-335: The Common Language Infrastructure (CLI) The importance of these documents becomes clear when you understand that they enable third parties to build distributions of the .NET platform for any number of operating systems and/or processors. ECMA-335 is perhaps the more meaty of the two specifications, so much so that is has been broken into five partitions, as shown in Table 1-5.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.