Appendix D. Common Utilities

Microsoft .NET Framework provides many tools to help developers make the best use of the Framework. In the following sections, we document the commonly used subset of .NET tools that we’ve used throughout this book:

  • Assembly Generation Utility (al.exe)

  • Assembly Registration Utility (gacutil.exe)

  • MSIL Assembler (ilasm.exe)

  • MSIL Disassembler (ildasm.exe)

  • C++ Compiler (cl.exe)

  • C# Compiler (csc.exe)

  • VB Compiler (vbc.exe)

  • PE File viewer (dumpbin.exe)

  • Type Library Exporter (tlbexp.exe)

  • Type Library Importer (tlbimp.exe)

  • XML Schema Definition Tool (xsd.exe)

  • Shared Name Utility (sn.exe)

  • Web Service Utility (wsdl.exe)

Assembly Generation Utility (al.exe)

al.exe is generally used to generate assemblies with manifests. Table D-1 shows some of the common uses of the Assembly Generation Utility.

Table D-1. Assembly Generation Utility common uses

Option

Description

/flags:flags

Specifies a value for the Flags field in the assembly.

0x0000: side-by-side compatible

0x0010: cannot execute with other versions in the same application domain.

0x0020: cannot execute with other versions in the same process

0x0030: cannot execute with other versions on the same computer

/help or /?

Use to get help for this command.

/keyfile:keyfilename or /keyf:keyfilename

Use to create shared components. keyfilename contains a key pair generated with the Shared Name Utility (sn.exe). The compiler inserts the public key into the assembly manifest and then signs the assembly with the private key.

/keyname:keycontainer or /keyn:keycontainer

Use to create shared components. keycontainer contains a key pair generated and installed into a key container with the Shared Name Utility (sn.exe). The compiler inserts the public key into the assembly manifest and then signs the assembly with the private key.

/main:entrymethod

Specifies the entry-point method name when converting a module to an executable.

/out:filename

Specifies the output filename.

/target:lib|exe|win or /t:lib|exe|win

Specifies the file format of the output file (lib for library, exe for console executable, and win for win32 executable). The default setting is lib.

/version:major.minor.revision.build

Specifies version information for the assembly. The default value is 0.

Assembly Registration Utility (gacutil.exe)

You can use gacutil.exe to install and uninstall an assembly, as well as to list the content of the GAC. Table D-2 shows some of the common uses of the Assembly Registration Utility.

Table D-2. Assembly Registration Utility common uses

Option

Description

/l

To list the content of the GAC.

/ldl

To list the content of the downloaded files cache.

/cdl

To clear the content of the downloaded file cache.

/i filename

To install an assembly with file named filename into the GAC.

/u assemblyname

To uninstall an assembly from the GAC by specifying the assembly name. If multiple versions of the same assembly exist, all of them will be removed unless a version is specified with the assemblyname (i.e., gac -u myAssembly,ver=1.0.0.1).

/h or /help or /?

To display command syntax and options.

MSIL Assembler (ilasm.exe)

This tool takes MSIL as input and generates a portable executable (PE) file containing the MSIL and the metadata required to run on the .NET Framework. This is most useful to vendors who would like to create MSIL-compliant compilers. All they have to do is write the compiler to translate the source language to MSIL. Ilsam.exe will take the second step to put the MSIL content into the PE format where it can be executed on the .NET Framework. The general syntax for MSIL assembler is:

ilasm [options] MSILfilename

Table D-3 shows some of the common uses of the assemblers.

Table D-3. Assemblers common uses

Option

Description

/debug

This option ensures that the output PE contains debugging information such as local variables, argument names, and line numbers. This is useful for debug build.

/dll

This option produces a .dll output.

/exe

This option produces an .exe output.

/listing

This option produces a listing of the output on STDOUT.

/output= filename

filename is the output filename.

/?

This option is used to obtain command-line help.

MSIL Disassembler (ildasm.exe)

This tool extracts the MSIL code from a PE file targeted for .NET Framework. The general syntax for this tool is:

Ildasm [options] PEFilename

Table D-4 shows some of the common uses of the disassembler.

Table D-4. Disassembler common uses

Option

Description

/linenum

This includes references to original source lines.

/output= filename

The output goes to a file instead of in a GUI dialog box.

/source

This shows original source lines as comments.

/text

The output goes in a console window.

/tokens

This shows metadata tokens of classes and members.

C++ Compiler (cl.exe)

Table D-5 shows some of the common uses of the C++ compiler.

Table D-5. C++ compiler common uses

Option

Description

/CLR

This option flags the compiler to compile .NET-runtime managed code.

/entry:methodname

For C++ managed code, this link setting should point to the main entry-point function.

/link

This option combines the compile and link steps.

/subsystem:|windows|windowsce|console|

This link option specifies the type of output.

/out:filename

This option allows for the output filename.

C# Compiler (csc.exe)

Table D-6 shows some of the common uses of the C# compiler.

Table D-6. C# compiler common uses

Option

Description

/debug

With this option, the compiler will emit debugging information in the output file.

/define:symbol or /d:symbol

This option is similar to C++. Use this option to define preprocessor symbols.

/doc:docname

docname is the XML output file for the autogenerated XML comment embedded in C# code.

/help

This option shows the command-line help for the C# compiler.

/main:classname

If there is more than one Main entry in different classes, you will have to specify the Main entry in which class you want the entry point of the application.

/out:filename

This option represents the output filename.

/reference:libname or /r:libname

This option allows single or multiple libraries be included with this compilation. For multiple libraries to be included, use a semicolon as the delimiter.

/target:exe|library|winexe|module or /t:exe|library|winexe|module

This option allows you to specify the type of the output: exe for console executables, library for DLLs, and winexe for Windows Form applications. When you set the target to module, the compiler outputs binary for the module but not a .NET assembly. Modules can be added to a .NET assembly later.

/unsafe

If you use unsafe keywords in your C# code, you will have to use this option when compiling your source.

Visual Basic Compiler (vbc.exe)

Table D-7 shows some of the common uses of the Visual Basic compiler.

Table D-7. Visual Basic compiler common uses

Option

Description

/debug

With this option, the compiler will emit debugging information in the output file.

/define:symbol or / d:symbol

Use this option to define preprocessor symbols.

/help or /?

This option shows the command-line help for the Visual Basic compiler.

/keycontainer:keycontainer

keycontainer specifies the key container that contains the key pair for signing the assembly. See sn.exe for information on generating the key container.

/keyfile:keyfile

keyfile specifies the key file that contains the key pair for signing the assembly. See sn.exe for information on generating the key file.

/main:classname

If there is more than one Main entry in different classes, you will have to specify the Main entry in which class you want the entry point of the application.

/out:filename

This option represents the output filename.

optionexplicit[+/-]

Turn on or off optionexplicit to enforce explicit or implicit declaration of variables. The default setting is on.

optionstrict[+/-]

Turn on or off optionstrict to disallow or allow casting with truncation. The default setting is on.

/reference:libname or /r:libname

This option allows single or multiple libraries be included with this compilation. For multiple libraries to be included, use a semicolon as the delimiter.

/target:exe|library|winexe|module or /t:exe|library|winexe|module

This option allows you to specify the type of the output: exe for console executables, library for DLLs, and winexe for Windows Form applications. When you set the target to module, the compiler outputs binary for the module but not a .NET assembly. Modules can be added to a .NET assembly later.

PE File Format Viewer (dumpbin.exe)

dumpbin is not a new utility. However, since .NET Framework stores the IL inside the extended PE format, this old utility is still very useful for examining the structure of executable or DLLs, as well as listing import and export entries of the binaries. The general syntax for this utility is:

Dumpbin [options] PEFilename

Table D-8 shows some of the common dumpbin uses.

Table D-8. Dumpbin common uses

Option

Description

/all

Displays all information from the PE file.

/exports

Displays all exports from the PE file.

/header

Displays the header information from the PE file.

/clrheader

Display the .NET Framework header information for an image built with /clr (see CL.exe).

/imports

Displays all imports for the PE file.

Type Library Exporter (tlbexp.exe)

Type library exporter and importer are the two tools necessary for COM interop. The exporter generates a type library for a .NET Framework assembly so that other COM components can interop with .NET components. The general syntax for tlbexp.exe is:

tlbexp AssemblyName [options]

Table D-9 shows some of the common uses of tlbexp.exe.

Table D-9. Type Library Exporter common uses

Option

Description

/nologo

This option suppresses the logo of the tlbexp executable.

/out:filename

filename is the name of the type library file.

/silent

This option suppresses all messages from the tlbexp executable.

/verbose

This option displays extra information while converting the component.

/? or /help

This option displays the help information for the tool.

Type Library Importer (tlbimp.exe)

Because it is the reverse tool of the type library exporter, the importer generates a .NET proxy component for a COM component so that .NET components can use legacy COM components. The general syntax for tlbimp.exe is:

tlbimp PEFile [options]

Table D-10 shows some of the common uses of tlbimp.exe.

Table D-10. Type Library Importer common uses

Option

Description

/keycontainer: keycontainer

This option signs the resulting assembly with the private key in the keycontainer. The public key in the keyfile will be used in the assembly manifest. See sn.exe for the keycontainer generation.

/keyfile: keyfile

This options signs the resulting assembly with the private key in the keyfile. The public key in the keyfile will be used in the assembly manifest. See sn.exe for keyfile generation.

/nologo

This option suppresses the logo of the tlbimp executable.

/out:filename

filename is the name of the type library file.

/silent

This option suppresses all messages from the tlbimp executable.

/unsafe

This option produces interfaces without .NET Framework security checks.

/verbose

This option displays extra information while converting the component.

/? or /help

This option displays the help information for the tool.

XML Schema Definition Tool (xsd.exe)

XML Schema Definition (XSD) is useful when working with XML schemas that follow the XSD language. With XSD, you can perform the following transformations:

  • XDR to XSD

  • XML to XSD

  • Classes to XSD

  • XSD to Classes

  • XSD to DataSet

XDR to XSD

To convert an XDR-formatted file to XSD, use the following syntax:

xsd [options] file.xdr

Note that the file extension .xdr dictates the conversion from XDR to XSD.

XML to XSD

To convert an XML-formatted file to XSD, use the following syntax:

xsd [options] file.xml

Note that the file extension .xml dictates the conversion from XML to XSD.

Classes to XSD

You can convert classes to XSD by specifying the runtime assembly file (.exe or .dll extension) as the filename to the utility. You can also specify a particular type within the assembly you want to convert to XSD using the /type flag. The typename can be a wildcard match. If you omit the /type flag, all types in the assembly will be converted. The syntax follows:

Xsd [/TYPE:typename] assemblyFile

or:

Xsd [/T:typename] assemblyFile

XSD to Classes

To convert XSD back to classes, use the /classes or /c flag. You can specify a particular element in the XSD schema to be converted to a class. You can also specify the language for the class source file. The general syntax follows:

xsd /CLASSES 
    /ELEMENT:element 
    /NAMESPACE:namespace
    /LANGUAGE:language /URI:uri file.xsd

or:

xsd /C E:element /N:namespace /L:language /U:uri file.xsd

Note that namespace, language, and uri can be specified only once.

XSD to DataSet

To convert XSD to dataset, use the /dataset or /d flag. Again, you can narrow down to a particular element in the XSD schema to be converted. The general syntax follows:

xsd /D [/DATASET] file.xsd

Strong Name Utility (sn.exe)

The Strong Name Utility (sn.exe) guarantees unique names for shared components because these components will end up in the GAC. Each shared component is signed with a private key and published with the public key. Table D-11 shows some common uses of sn.exe.

Table D-11. Strong Name Utility common uses

Option

Description

/?

This option displays more command-line help.

-d keycontainer

This option is used to remove the keycontainer from the CSP.

-i keyfile keycontainer

This option reads the key pair in keyfile and installs it in the key container keycontainer in the Cryptographic Service Provider (CSP).

-k keyfile

This option generates a new key pair and writes it to keyfile.

-v assembly

This option is used to verify the shared name in an assembly.

Web Service Utility (wsdl.exe)

wsdl.exe helps create ASP.NET web services and proxies for their clients. The most common usage of wsdl.exe is to generate proxy classes for Web services:

wsdl 
     /language:language 
     /namespace:namespace 
     /out:output 
     /protocol:protocol
                 path
         

The path parameter is a local path to a service-description file or URI where the SDL file can be retrieved. The language parameter specifies the language for the output-proxy source file. It can be C#, VB, JS or VJS. The generated class will be in the specified namespace. The output source file is controlled by the output option. The protocol controls which protocol the proxy will use to communicate with the Web Service. The choices of protocols provided by the .NET Framework are SOAP, SOAP12, HttpGet, and HttpPost. You can also have your own protocol here if you’ve extended the WebClientProtocol or HttpWebClientProtocol class.

For short names options, use the following:

wsdl 
     /l:language 
     /n:namespace 
     /o:output 
     /protocol:protocol
                 path
         

The rest of the syntax can be obtained with wsdl /?.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.125.219