1. 程式人生 > 其它 >使用csc.exe編譯cs檔案為dll

使用csc.exe編譯cs檔案為dll

參考:https://www.xp.cn/b.php/85332.html

https://www.cnblogs.com/alexyuyu/archive/2010/05/09/1731070.html

全指令為:C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /target:library /out:Class1.dll /res:activity.config.xml *.cs

具體操作方式,呼叫C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe,引數/target:library為生成類庫,/out:Class1.dll為指定輸出檔名,/res:activity.config.xml為嵌入指定的資源,*.cs為編譯所有的cs檔案。

附上Visual C# 編譯器選項

                        - 輸出檔案 -
/out:<檔案>                    指定輸出檔名(預設值: 包含主類的檔案或第一個檔案的基名稱)
/target:exe                    生成控制檯可執行檔案(預設) (縮寫: /t:exe)
/target:winexe                 生成 Windows 可執行檔案 (縮寫: /t:winexe)
/target:library                生成庫 (縮寫: /t:library)
/target:module                 生成能新增到其他程式集的模組 (縮寫: /t:module)
/target:appcontainerexe        生成 Appcontainer 可執行檔案 (縮寫: /t:appcontainerexe)
/target:winmdobj               生成 WinMDExp 使用的 Windows 執行時中間檔案 (縮寫: /t:winmdobj)
/doc:
<檔案> 要生成的 XML 文件檔案 /platform:<字串> 限制可以在其上執行此程式碼的平臺: x86、Itanium、x64、arm、anycpu32bitpreferred 或 anycpu。預設值為 anycpu。 - 輸入檔案 - /recurse:<萬用字元> 根據萬用字元規範,包括當前目錄和子目錄下的所有檔案 /reference:<別名>
=<檔案> 使用給定的別名從指定的程式集檔案引用元資料 (縮寫: /r) /reference:<檔案列表> 從指定的程式集檔案引用元資料 (縮寫: /r) /addmodule:<檔案列表> 將指定的模組連結到此程式集中 /link:<檔案列表> 嵌入指定的互操作程式集檔案中的元資料 (縮寫: /l) - 資源 - /win32res:<檔案> 指定 Win32 資原始檔(.res) /win32icon:<檔案> 對輸出使用此圖示 /win32manifest:<檔案> 指定 Win32 清單檔案(.xml) /nowin32manifest 不包括預設 Win32 清單 /resource:<資源資訊> 嵌入指定的資源 (縮寫: /res) /linkresource:<資源資訊> 將指定的資源連結到此程式集 (縮寫: /linkres) 其中 resinfo 的格式是 <file>[,<string name>[,public|private]] - 程式碼生成 - /debug[+|-] 發出除錯資訊 /debug:{full|pdbonly} 指定除錯型別(“full”是預設型別,可以將除錯程式附加到正在執行的程式) /optimize[+|-] 啟用優化 (縮寫: /o) - 錯誤和警告 - /warnaserror[+|-] 將所有警告報告為錯誤 /warnaserror[+|-]:<警告列表> 將特定警告報告為錯誤 /warn:<n> 設定警告等級(0-4) (縮寫: /w) /nowarn:<警告列表> 禁用特定的警告訊息 - 語言 - /checked[+|-] 生成溢位檢查 /unsafe[+|-] 允許“不安全”程式碼 /define:<符號列表> 定義條件編譯符號 (縮寫: /d) /langversion:<字串> 指定語言版本模式: ISO-1、ISO-2、3、4、5 或 Default - 安全性 - /delaysign[+|-] 僅使用強名稱金鑰的公共部分對程式集進行延遲簽名 /keyfile:<檔案> 指定強名稱金鑰檔案 /keycontainer:<字串> 指定強名稱金鑰容器 /highentropyva[+|-] 啟用高平均資訊量的 ASLR /enforcecodeintegrity[+|-] Enforce code intergrity checks on all inputs to the compiler and enable loading compiled assemblies by other programs that enforce code integrity if the operating system is configured to do so. - 雜項 - @<檔案> 有關更多選項,請閱讀響應檔案 /help 顯示此用法資訊 (縮寫: /?) /nologo 取消編譯器版權資訊 /noconfig 不要自動包含 CSC.RSP 檔案 - 高階 - /baseaddress:<地址> 要生成的庫的基址 /bugreport:<檔案> 建立“Bug 報告”檔案 /codepage:<n> 指定開啟原始檔時要使用的內碼表 /utf8output 以 UTF-8 編碼格式輸出編譯器訊息 /main:<型別> 指定包含入口點的型別(忽略所有其他可能的入口點) (縮寫: /m) /fullpaths 編譯器生成完全限定路徑 /filealign:<n> 指定用於輸出檔案節的對齊方式 /pdb:<檔案> 指定除錯資訊檔名(預設值: 副檔名為 .pdb 的輸出檔名) /errorendlocation 輸出每個錯誤的結束位置的行和列 /preferreduilang 指定首選輸出語言名稱。 /nostdlib[+|-] 不引用標準庫(mscorlib.dll) /subsystemversion:<字串> 指定此程式集的子系統版本 /lib:<檔案列表> 指定要在其中搜索引用的附加目錄 /errorreport:<字串> 指定如何處理內部編譯器錯誤: prompt、send、queue 或 none。預設值為 queue。 /appconfig:<檔案> 指定一個包含程式集繫結設定的應用程式配置檔案 /moduleassemblyname:<字串> 此模組所屬程式集的名稱