VS C#命令行编译工具CSC使用入门
2016-04-22 11:19
260 查看
VS C#命令行编译工具CSC使用入门
撰写日期:2016/04/21更新日期:2016/04/21
博客地址:http://www.cnblogs.com/gibbonnet/p/5420548.html
CSC.exe: Visual C# Compiler
任务场景
调试
多文件编译
生成DLL/引用DLL
资源
官方文档:https://msdn.microsoft.com/en-us/library/2fdbz5xd.aspx
任务
为CSC设置环境变量
运行VSVARS32.BAThttps://msdn.microsoft.com/en-us/library/1700bbwd.aspx
部署程序
安装.NET: https://msdn.microsoft.com/en-us/library/ee942965.aspxDeploying Applications, Services, and Components: https://msdn.microsoft.com/en-us/library/wtzawcsz.aspx
基本操作
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 My.exe: csc /out:My.exe File.cs Compiles all 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 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 the C# files in the current directory to Something.xyz (a DLL): csc /target:library /out:Something.xyz *.cs
调试
多文件编译
csc /define:DEBUG /optimize /out:File2.exe *.cs
模块化
知识:运行时如何定位汇编程序生成和引用DLL
csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
csc /target:library /out:lib/Class1.dll Class1.cs csc /lib:lib /reference:Class1.dll HelloWorld.cs
但是HelloWorld.exe运行时,需要和Class1.dll在同一个目录
The /reference option causes the compiler to import public type information in the specified file into the current project, thus enabling you to reference metadata from the specified assembly files.
/reference:[alias=]filename /reference:filename
The /lib option specifies the location of assemblies referenced by means of the /reference (C# Compiler Options) option.
/lib:dir1[,dir2]
问题:如何引用多个DLL?
什么是Module:https://social.msdn.microsoft.com/Forums/zh-CN/79dbe468-b0b5-47da-9012-40f83a989465/what-does-it-mean-by-a-module-reference-in-c?forum=netfxbcl
Module VS Assembly:Module是编译单元,Assemly是部署单元。
https://social.msdn.microsoft.com/Forums/en-US/c83f174d-03f4-4b4c-930c-2d2a4dc54356/using-modules-netmodule?forum=Vsexpressvcs
命令行选项
输出文件:输出文件名、生成目标类型、生成文档地址、平台输入文件:包含文件、引用元数据、链接模块、嵌入元数据、分析器
资源:win32资源、win32图标、win32声明文件、嵌入特特定资源
代码生成:??
错误和警告:
语言
安全
其他
高级
输出选项
输出选项:/target:appcontainerexe, /target:exe, /target:library, /target:module, /target:winexe, or /target:winmdobj/target:appcontainerexe To create an .exe file for Windows 8.x Store apps. /target:exe To create an .exe file. /target:library To create a code library. /target:module To create a module. /target:winexe To create a Windows program. /target:winmdobj To create an intermediate .winmdobj file.
参考:按类别排序的命令行选项 https://msdn.microsoft.com/en-us/library/6s2x2bzy.aspx
外接
linker
al.exe:Microsoft(R) Assembly Linkeral是不是具有将多个module合成一个dll的功能?
SCSC 2.0
使用 C# 2.0 命令行编译器代码注释与生成文档
官方参考:https://msdn.microsoft.com/en-us/library/5ast78ax.aspx范例:
using System; namespace gibbon.learning.csc { /// /// Summary description for App. /// class App { /// Main Method static void Main(string[] args) { // Class Class1.SayHello Class1.SayHello("Hello VS C# .NET"); } } /// <summary> /// Class1具有sayHello静态方法 /// </summary> class Class1 { /// <summary> /// sayHello方法 /// <param name="message">消息</param> /// <returns>结果</returns> /// </summary> public static int SayHello(string message) { Console.WriteLine(message); return 0; } } }
生成的XML
<?xml version="1.0"?> <doc> <assembly> <name>DemoCommont</name> </assembly> <members> <member name="T:gibbon.learning.csc.App"> Summary description for App. </member> <member name="M:gibbon.learning.csc.App.Main(System.String[])"> Main Method </member> <member name="T:gibbon.learning.csc.Class1"> <summary> Class1具有sayHello静态方法 </summary> </member> <member name="M:gibbon.learning.csc.Class1.SayHello(System.String)"> <summary> sayHello方法 <param name="message">消息</param> <returns>结果</returns> </summary> </member> </members> </doc>
相关文章推荐
- VS2010远程调试C#程序
- c#中winform窗体之间的传值
- C# Math.Round中国式的四舍五入法
- C#委托
- C# 非常有用的方法和短句
- C#多线程编程
- C#,数据类型转换,装箱与拆箱概念,数据类型转换方法
- C#界面设计之树目录TreeView的使用
- C#读取 文本文件 写入textbox
- C#实现文本文件读写方法汇总
- C#关于输入输出流的知识点
- C#遍历指定文件夹中的所有文件
- C# 图片旋转360度程序
- C# 中反射获取某类的子类和根据类型名动态创建对象(转载)
- C# 排列组合
- C#字符串转日期格式
- 细说C#多线程那些事 - 线程同步和多线程优先级
- C#中的线程(一)入门
- C# class示例 0012
- XML转换