《命令行环境学习C#指南.doc》由会员分享,可在线阅读,更多相关《命令行环境学习C#指南.doc(4页珍藏版)》请在金锄头文库上搜索。
1、命令行环境学习C#指南网上命令行学习c#的文章挺琐碎,所以我在这里整理一下程序,方便大家一、安装准备工作,该打的sp都打好,MS要求win2k安装 Service Pack 3NT 4.0 要Service Pack 6aiis要5.0或者更高版本然后到MS网站上下载安装1)安装 Microsoft .NET Framework Redistributable Packagedotnetfx.exe 20多M,安装所需的硬盘空间:160 MB所需的硬盘空间:70 MB这是.NET应用程序的运行环境2)安装.NET Framework SDKsetup.exe 100多M安装所需的硬盘空间:60
2、0 MB所需的硬盘空间:370 MB这是开发环境、文档和例子3)安装.NET Framework Language Pack (可选)langpack.exe 1M多网站上的说明:NET Framework 语言包包含翻译为非英语语言的文本,如错误信息之类的文本。在非英语操作系统中运行 .NET Framework 应用程序并不需要安装语言包;但是,如果您想用英语之外的一种语言查看 .NET Framework UI 资源,就需要这种语言的语言包了。在一台计算机上可以安装多个语言包,每种语言一个语言包。二、环境变量设置假定你将.net framework安装在E盘,在E:Program Fil
3、esMicrosoft.NETSDKv1.1Bin目录下会有个环境变量批处理文件sdkvars.bat,将它加到你的系统环境变量中或者在每次打开console时加载。我本人习惯后者,方法是复制一个console的快捷方式到桌面,右键点击,在属性中将目标该为%SystemRoot%system32cmd.exe /k 地址sdkvars.bat;起始目录可以填入平时存放代码的目录 。因为在这里不支持长文件名,为方便起见我一般将sdkvars.bat复制一份为csharp.bat到根目录,所以目标中填入%SystemRoot%system32cmd.exe /k e:sdkvars.bat。这样以
4、后每次双击图标,就可以在命令行工作了。三、命令行工具使用用文本编辑器编辑好你的程序,然后用命令行编译之类关于命令行的使用,下面是OReilly有本书的一段,够用了The .NET Framework SDK contains many useful programming tools. Here, in an alphabetical list,are those we have found most useful or necessary for developing C# applications. Unless otherwise noted, the tools in this lis
5、t can be found either in the bin directory of your .NET Framework SDK installation or in the %SystemRoot%Microsoft.NETFrameworkVERSION directory (replace VERSION with the framework version). Once the .NET Framework is installed, you can access these tools from any directory. To use any of these tool
6、s, invoke a Command Prompt window and enter the name of the desired tool. For a complete list of the available command-line switches for any given tool, enter the tool name (e.g., csc) and press the Return or Enter key.ADepends.exe: assembly dependency listAdepends displays all assemblies that a giv
7、en assembly is dependent on to load. This is a useful C# program found among the samples in the Tool Developers Guide directory beneath the .NET Framework or Visual Studio .NET directory tree. You need to install these samples before you can use them, because they are not installed by default.Al.exe
8、: assembly linking utilityCreates an assembly manifest from the modules and resources files you name. You canalso include Win32 resources files. Heres an example:al /out:c.dll module moduleCorDbg.exe : runtime debuggerGeneral source-level, command-line debug utility for MSIL programs. Very useful to
9、ol for C# source debugging. Source for cordbg is available in the Tool Developers Guide directory.Csc.exe: C# compilerCompiles C# sources and incorporates resource files and separately compiled modules.Also allows you to specify conditional compilation options, XML documentation, and path informatio
10、n. Here are some examples:csc foo.cs /r:bar.dll /win32res:foo.rescsc foo.cs /debug /define:TEMPDbgClr.exe: GUI debuggerWindows-based, source-level debugger. Available in the GuiDebug directory of the .NET Framework SDK installation.GACUtil.exe: global assembly cache utilityAllows you to install, uni
11、nstall, and list the contents of the global assembly cache. Heres an example:gacutil /i c.dllILAsm.exe: MSIL assemblerCreates MSIL modules and assemblies directly from an MSIL textual representation.ILDasm.exe : MSIL disassemblerDisassembles modules and assemblies. The default is to display a tree-s
12、tylerepresentation, but you can also specify an output file. Here are some examples:ildasm b.dllildasm b.dll /out=b.asmInstallUtil.exe: installer utilityExecutes installers and uninstallers contained within the assembly. A logfile can be written, and state information can be persisted.Ngen.exe: nati
13、ve image generatorCompiles an assembly to native code and installs a native image in the local assembly cache. That native image is used each time you access the original assembly, even though the original assembly contains MSIL. If the runtime cant locate the native image,it falls back on JIT compi
14、lation. Here are some examples:ngen foo.exengen foo.dllnmake.exe: make utilityCommon utility that scripts building of multiple components and source files and tracks rebuild dependency information. See Appendix E for more information.PEVerify.exe: portable executable verifierVerifies that your compi
15、ler has generated type-safe MSIL. C# will always generate typesafe MSIL. Useful interop with ILASM-based programs.RegAsm.exe: register assembly toolRegisters an assembly in the system registry. This allows COM clients to call managed methods. You can also use it to generate the registry file for fut
16、ure registration. Heres an example:regasm /regfile:c.reg c.dllRegSvcs.exe : register services utilityRegisters an assembly to COM+ 1.0, and installs its typelib into an existing application. Can also generate a typelib. Heres an example:regsvcs foo.dll /appname:comapp /tlb:newfoo.tlbSn.exe : shared name utilityVerifies ass