Chapter 2 build C # applications
Build. NET applications have many tools to choose from, from the simple c # command line editor CSC. EXE and notepad are used in combination, to the lightweight Editor (textpad and notepad ++), and the open-source IDE development tool sharpdevelop, and then to the commercial use of Microsoft.. NET development tools, visual studio 2008, etc.
2.1 CSC command line compiler
For many programmers, VS is used in the first place. as a development platform, NET does not or seldom uses the command line compiler. In fact, all development platforms ultimately call the command line compiler, but this process is transparent to users, however, understanding the command line compilation method is essential for a Senior Programmer!
The csung language uses csc.exe,vb.netand vbc.exe for compiling. Here, only csc is used as an example.
In the command line compiler, flag writing is supported, such as csc/out and csc/t. In addition, you can use "-" or "/" to access the flag or option.
To compile a source code (use NotePad to edit it), run the CSC command.
Two types of parameters are generally required:
Input is the name of the source file to be compiled, for example, *. CS. If multiple files need to be compiled, columns them one by one. If you compile all *. CS files, you only need to use wildcards, such as csc *. cs.
The output parameter is the file to be compiled. The options are exe and dll or module. You can view the specific parameters.
It should be noted that dll is a dynamic link library and cannot be run directly. It must be hosted in other executable programs.
Exe files can be run directly. Dll can be embedded in exe. The difference is that there must be an entry point for the exe file.
The default file is the exe file, but if there is no entry point, an error will be prompted. Source code with entry points can be compiled into dll or exe.
When multiple source codes, such as csc *. cs, are compiled into a file (optional dll or exe ).
That is, if the compiled source code references the classes in other assembly, you need to add the reference option to let the compiler know how to locate the Assembly and reference it, this is equivalent to using the project-referenced assembly in IDE.
Including referencing a single assembly and multiple assembly (separated by semicolons ).
In addition, to reduce the input burden, you can also create a response file (*. rsp), which records all the commands used during compilation. The system also provides a default response file (c #'s default csc. rsp), which contains some commonly used reference assembly, which is automatically referenced when being compiled by csc.
Note: The response file is accumulative. If the response file to be loaded later conflicts with the previous one, the corresponding code will be overwritten.
Note: When an unused assembly is referenced, the compiler ignores it. Therefore, there is no need to worry that too many unused Assembly references will affect performance. Of course, as a specification, there is no need to reference unused assembly. (So it can be understood that many useless programming sets and using are referenced in many namespaces without affecting the performance)
2.2 Other Compilers
To improve the efficiency of development and compilation, many development platforms are provided. In essence, they still use the command line compiler for background work, but they do not need to be manually completed by developers, forming an automated workflow.
For example, textpad (charged but not limited), notepad ++ (free), sharpdevelop (free), visual c # express (quick version, free), visual studio 2008 (commercial version, fees are charged. This article mainly describes some practical functions of vs2008:
(1) The current version 2008 supports selecting the Framework Version (2.0/3.0/3.5) when creating a project. This function is good, at last, we don't need to install multiple development platforms of vs on one machine.
(2) 2008 provides a refactoring function, which is very practical and can improve existing code and automate many previous manual work.
(3) code extension and surrounding technology. With the ability to insert pre-fabricated c # code blocks, the number of available code extensions is amazing!
(4) Visualized Class Designer (this function is not available in express ). After creating a class chart file, you can use the tool in the toolbox to drag and drop various types and interfaces, and add and delete members to indicate various types of relationships (inheritance, etc ), combined with the practical class details window and class designer toolbox, the design speed is improved.
(5) object testing platform. Provides a visual tool (OTB, object testing platform) to quickly create a class instance and call its members without running the entire program (I personally think this functionVery practical, It seems that only the VS of the Team version is available ). This is useful if you need to test a specific method instead of executing other unrelated code line by line. You do not expect to compile this program for dozens of seconds to test a relatively independent module!
Currently, from the book, this operation only requires one step. Right-click the class instance in OTB under the Class View, select-call method, and select a method to execute. In fact, you still need to step before you can see the OTB window, that is, right-click the Class View, select create instance, and enter an Instance name. In this way, the OTB window will appear below, to call the method. As shown in: