Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
APPENDIX
Command-Line Syntax
In addition to the compilers for C# (csc.exe), C++ (cl.exe), and VB .NET (vbc.exe) the Microsoft .NET Framework SDK adds a number of tools designed to make it easier for you to create, deploy, and manage applications and components that target the .NET Framework. This appendix will introduce these tools and will also detail the command-line usages of csc.exe.
Command Utilities In order to be able to run these command-line utilities, you must configure the environment properly. The Visual Studio .NET installation includes a command file (VCVARS32.BAT) that configures the command environment properly. The command file is installed in the \bin directory of your installation (the default is c:\Program Files\Microsoft Visual Studio.NET\vc7\bin). The command file is configured during the installation of Visual Studio to correspond to your computer’s set-up. Do not replace a missing or damaged VCVARS32.bat file with a VCVARS32.bat from another machine. Rerun setup to replace the missing file. To run VCVARS32.BAT you can execute it from the path or you can use the shortcut. Select Start | Programs | Microsoft Visual Studio .NET | Visual Studio .NET Tools | Visual Studio .NET Command Prompt. TIP We recommend that you create a shortcut to the .NET command prompt on your desktop and in the Windows taskbar.
The .NET Framework SDK tools are grouped according to use: • Debugging tools (see Table C-1) • Configuration and deployment tools (see Table C-2) • Security tools (see Table C-3) • General tools (see Table C-4)
1 P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:13 AM
C
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide
2 Debugging Tools Tool
Description
Microsoft CLR Debugger (DbgCLR.exe)
Provides debugging services with a graphical interface to help application developers find and fix bugs in programs that target the runtime. Provides command-line debugging services using the Common Language Runtime Debug API. It is used to find and fix bugs in programs that target the runtime.
Runtime Debugger (Cordbg.exe)
Table C-1
The .NET Framework SDK Debugging Tools
Configuration and Deployment Tools Tool
Description
Assembly Cache Viewer (Shfusion.dll)
Lets you to view and manipulate the contents of the Global Assembly Cache using Windows Explorer. Allows you to use either resource files or Microsoft Intermediate Language (MSIL) files to generate a file with an assembly manifest. Registers .NET Framework classes to the Registry, which allows COM clients to create .NET Framework classes transparently. Displays log-file information for failed assembly binding. This information can help you diagnose the reasons the .NET Framework has problems locating an assembly at run time. This tool allows you to view and manipulate the contents of the Global Assembly Cache and download cache. You can use Gacutil.exe in build scripts, makefile files, and batch files. Allows you to install and uninstall server resources by executing the installer components of a specified assembly. Displays and manages all existing stores for the currently logged-on user. Lets you create a native image from a managed assembly and install the image in the native image cache on the local computer.
Assembly Linker (Al.exe)
Assembly Registration tool (Regasm.exe)
Assembly Binding Log Viewer (Fuslogvw.exe)
Global Assembly Cache tool (Gacutil.exe)
Installer tool (Installutil.exe)
Isolated Storage tool (Storeadm.exe) Native Image Generator (Ngen.exe)
Table C-2
P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:13 AM
The .NET Framework SDK Configuration and Deployment Tools
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
Appendix C: Command-Line Syntax
3 Tool
Description
.NET Framework Configuration tool (Mscorcfg.msc)
Provides a graphical interface for managing .NET Framework security policy and applications that use remoting services. This tool also allows you to manage and configure assemblies in the Global Assembly Cache. Allows you to add managed classes to Windows 2000 Component Services (COM+) by loading and registering the assembly and generating, registering, and installing the type library into an existing COM+ 1.0 application. Lets you compile client applications that communicate with XML web services. The technique used is called remoting. Generates a type library from a Common Language Runtime assembly. Converts the type definitions found within a COM type library into equivalent definitions in managed metadata format. Generates the code for XML web services and XML web service clients, XML Schema Definition (XSD) schema files, and the .disco discovery documents from WSDL (Web Services Description Language) contract files. Allows you to discover the URLs of XML web services located on a web server. Generates XML schemas that follow the XSD language proposed by the World Wide Web Consortium (W3C). This tool generates Common Language Runtime classes and DataSet classes from an XSD schema file.
.NET Services Installation tool (Regsvcs.exe)
Soapsuds tool (Soapsuds.exe)
Type Library Exporter (Tlbexp.exe) Type Library Importer (Tlbimp.exe)
Web Services Description Language tool (Wsdl.exe)
Web Services Discovery tool (Disco.exe) XML Schema Definition Tool (Xsd.exe)
Table C-2
The .NET Framework SDK Configuration and Deployment Tools (continued)
Security Tools Description
Certificate Creation Tool (Makecert.exe)
Creates X.509 certificates for testing purposes only. Manages certificates, certificate trust lists (CTLs), and certificate revocation lists (CRLs). Verifies the validity of a file signed with an X.509 certificate.
Certificate Manager tool (Certmgr.exe) Certificate Verification tool (Chktrust.exe) Table C-3
The .NET Framework SDK Security Tools
P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:14 AM
PART VII
Tool
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide
4 Tool
Description
Code Access Security Policy tool (Caspol.exe)
Allows you to examine and modify security policies for the machine, user, and enterprise-level code access. Signs a portable executable (PE) file with an Authenticode digital signature. Allows you to view the minimal, optional, and refused permission sets requested by an assembly. You can also use this tool to display the declarative security used by an assembly. Conducts MSIL type-safety verification checks and metadata validation checks on an assembly. Extracts public-key information or Authenticode publisher certificates from an assembly. The output is formatted so it can be incorporated into code. Allows you to change the Registry settings for the Software Publishing State keys. Tests a Software Publisher’s Certificate (SPC), or creates an SPC from one or more X.509 certificates. Allows you to create assemblies with strong names.
File Signing tool (Signcode.exe) Permissions View tool (Permview.exe)
PEVerify tool (PEverify.exe) Secutil tool (Secutil.exe)
Set Registry Tool (Setreg.exe) Software Publisher Certificate Test tool (Cert2spc.exe) Strong Name tool (Sn.exe) Table C-3
The .NET Framework SDK Security Tools (continued)
General Tools Tool
Description
Common Language Runtime Minidump tool (Mscordmp.exe)
Creates a file containing a core dump of information that can be useful when analyzing system issues in the runtime. Allows you to create a .licenses file that can be embedded in a Common Language Runtime executable. It reads text files that contain licensing information. Allows you to quickly generate an early-bound class for a specified Windows Management Instrumentation (WMI) class. Generates a PE file from Microsoft Intermediate Language (MSIL). Produces a MSIL source file from a Portable Executable (PE) file.
License Compiler (Lc.exe)
Management Strongly Typed Class Generator (Mgmtclassgen.exe) MSIL Assembler (Ilasm.exe) MSIL Disassembler (Ildasm.exe) Table C-4
P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:14 AM
The .NET Framework SDK General Tools
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
Appendix C: Command-Line Syntax
5 Tool
Description
Resource File Generator tool (Resgen.exe)
Converts text files and .resx (XML-based resource format) files to .NET Common Language Runtime binary .resources files that can be embedded in a runtime binary executable or compiled into satellite assemblies. Converts type definitions in a COM type library for an ActiveX control into a Windows Forms control. Finds managed classes matching a specified search pattern, and displays information about those classes using the Reflection API. Allows you to quickly and easily localize the Windows Forms forms in your application using a GUI tool.
Windows Forms ActiveX Control Importer (Aximp.exe) Windows Forms Class Viewer (Wincv.exe)
Windows Forms Resource Editor (Winres.exe) Table C-4
The .NET Framework SDK General Tools (continued)
C# Compiler (csc.exe) In order to compile and run a C# program, you will need to have the .NET Framework installed on your computer. Microsoft has made the .NET Framework available as a free upgrade, and you can either download it from http://msdn.microsoft.com (approximately 130MB) or order a CD with the .NET Framework. After installation, the C# compiler is available from the command prompt to create Portable Executable (PE) files from your source files (see the previous “Command Utilities” section for information on how to set up the environment for use with command-line tools). Using the C# Compiler (csc.exe) is rather complicated because it has a large family of command line options that control the behavior of the compiler. The next section will give you an overview of most of the command-line switches that are available.
csc Command-Line Syntax In Table C-5, you can see all the command-line switches understood by the C# compiler. To get an instant listing of the command-line switches, you only need to execute the csc.exe program with the /help switch to produce the following listing:
P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:14 AM
PART VII
C:\>csc /help Microsoft (R) Visual C# .NET Compiler version 7.00.9466 for Microsoft (R) .NET Framework version 1.0.3705 Copyright (C) Microsoft Corporation 2001. All rights reserved. Visual C# .NET Compiler Options - OUTPUT FILES /out: Output file name (default: base name of file with main class or first file) /target:exe Build a console executable (default) (Short form: /t:exe) …
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide
6 Description
@ /? /addmodule /baseaddress /bugreport /checked /codepage /debug /define /doc /filealign /fullpaths /help /incremental /lib /linkresource /main /nologo /nostdlib /noconfig /nowarn /optimize /out /recurse /reference /resource /target
/unsafe /utf8output /warn /warnaserror /win32icon /win32res Table C-5
P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:14 AM
Specify a response file. List compiler options to stdout. Specify one or more modules to be part of this assembly. Specify the preferred base address at which to load a DLL. Create a file that contains information that makes it easy to report a bug. Specify whether integer arithmetic that overflows the bounds of the data type will cause an exception at run time. Specify the code page to use for all source-code files in the compilation. Emit debugging information. Define preprocessor symbols. Process documentation comments to an XML file. Specify the size of sections in the output file. Specify the absolute path to the file in compiler output. List compiler options to stdout. Enable incremental compilation of source-code files. Specify the location of assemblies referenced via /reference. Create a link to a managed resource. Specify the location of the Main() method. Suppress compiler banner information. Do not import standard library (mscorlib.dll). Do not compile with the global or local versions of csc.rsp. Suppress the compiler’s ability to generate specified warnings. Enable or disable optimizations. Specify output file. Search subdirectories for source files to compile. Import metadata from a file that contains an assembly. Embed a .NET Framework resource into the output file. Specify the format of the output file using one of four options: /target:exe /target:library /target:module /target:winexe Compile code that uses the unsafe keyword. Display compiler output using UTF-8 encoding. Set warning level. Promote warnings to errors. Insert an .ico file into the output file. Insert a Win32 resource into the output file.
The csc.exe Command-Line Switches
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter C All-In-One
Appendix C: Command-Line Syntax
7 Examples The C# compiler commands can be typed in at the command-line prompt or as part of command files used to build the application. The following examples are executed from the command prompt: • Compiles File.cs producing File.exe: csc File.cs
• Compiles File.cs producing File.dll: csc /target:library File.cs
• Compiles File.cs and creates Hence.exe: csc /out:Hence.exe File.cs
• Compiles all of the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe: csc /define:DEBUG /optimize /out:File2.exe *.cs
• Compiles all of the C# files in the current directory, producing a debug version of File2.dll. No logo and no warnings are displayed: csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
• Compiles all of the C# files in the current directory to Thusly.hence (a DLL): csc /target:library /out:Thusly.hence *.cs
PART VII
P:\010Comp\All-in-1\443-6\appc.vp Monday, August 26, 2002 11:57:14 AM