dNet命令行编译命令CSC使用详细图解
下面先給出編譯示例的代碼;
add.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestClaclulate { class Program { static void Main(string[] args) { // 1,定義double變量 double numberOne; double numberTwo; // 2,從控制臺獲得兩個數 try { numberOne = double.Parse(Console.ReadLine()); numberTwo = double.Parse(Console.ReadLine()); // 3,輸出這兩個數的加,減,乘,除 的結果 Console.WriteLine(numberOne + " + " + numberTwo + " = " + (numberOne + numberTwo)); Console.WriteLine(numberOne + " - " + numberTwo + " = " + (numberOne - numberTwo)); Console.WriteLine(numberOne + " * " + numberTwo + " = " + (numberOne * numberTwo)); Console.WriteLine(numberOne + " / " + numberTwo + " = " + (numberOne / numberTwo)); } catch (System.FormatException e) { Console.WriteLine(e.Message); } // Console.ReadKey(); } } }main.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using 讀寫ini文件;class Program{static void Main(string[] args){string Current;Current = Directory.GetCurrentDirectory();//獲取當前根目錄Console.WriteLine("Current directory {0}", Current);// 寫入iniIni ini=new Ini(Current+"/config.ini");ini.Writue("Setting","key1","hello word!");ini.Writue("Setting","key2","hello ini!");ini.Writue("SettingImg", "Path", "IMG.Path");// 讀取inistring stemp = ini.ReadValue("Setting","key2");Console.WriteLine(stemp); Console.ReadKey();} }
編譯第一個cs文件,執行情況如下;
編譯為dll,第一次代碼中少了一個大括號,第二次成功;編譯后的dll見下圖;
編譯add.cs為my.exe;編譯和執行情況如下;
通過使用優化和定義 DEBUG 符號,編譯當前目錄中所有的 C# 文件;
第一次代碼中少了一個大括號;
第二次缺少命名空間引用;第三次main.cs缺少對inioper的命名空間引用;
第四次成功;
執行情況;
/define 選項的效果與在源文件中使用 #define 預處理器指令一樣。符號一直保持定義到源文件中的 #undef 指令移除定義,或者編譯器執行到文件尾。
參見
https://msdn.microsoft.com/zh-cn/library/0feaad6z(VS.80).aspx
一個示例的代碼和執行情況如下;
// preprocessor_define.cs // compile with: /define:xx // or uncomment the next line #define xx using System; public class Test {public static void Main() {#if (xx) Console.WriteLine("xx defined");#elseConsole.WriteLine("xx not defined");#endif} }
使用響應文件;編譯命令存在響應文件中;#開頭的行在rsp文件中是注釋;
resp1.rsp
# 這是一個簡單的響應文件,文件名稱為resp1.rsp # 使用方法: csc @resp1.rsp /target:exe /out:respadd.exe add.cs
執行情況,跟csc直接編譯的一樣;
編譯為DLL時指定DLL載入首選基地址;編譯情況如下圖;
用PEInfo打開上述DLL,看紅線處,優先裝載地址是在編譯命令中指定的;
編譯時把bug信息輸出的一個文件中;
打開debug開關,將會生成pdb文件;
編譯時同時為應用程序生成一個xml文檔;
增量編譯,按網上資料打的命令,提示出錯,下次再搞;增量編譯是僅僅編譯改變后的代碼,同時生成.incr文件;
編譯時指定一個圖標;如下圖,編譯后的應用程序將具有一個圖標;
相關鏈接:
http://wuyisky.cnblogs.com/archive/2007/07/03/804157.html
http://www.cnblogs.com/shuang121/archive/2012/12/24/2830874.html
總結
以上是生活随笔為你收集整理的dNet命令行编译命令CSC使用详细图解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Adobe Flash Builder
- 下一篇: C#访问SQLServer增删改查代码实