当前位置: 代码迷 >> ASP.NET >> 在asp.net2.0中,怎么将一个类(.cs)文件编译成.dll文件
  详细解决方案

在asp.net2.0中,怎么将一个类(.cs)文件编译成.dll文件

热度:5563   发布时间:2013-02-26 00:00:00.0
在asp.net2.0中,如何将一个类(.cs)文件编译成.dll文件?
如题:希望能给出比较详细的说明。谢谢。

------解决方案--------------------------------------------------------
1、写好代码先,编译成DLL文件,用C#写的CS文件需要用Framework中的CSC命令编译,编译步骤为:

2、在命令工具中输入 csc /t:library /r:System.Web.dll /r:System.dll /out: 目标文件名 源路径\源文件名。
csc /target:library /out:e:\cyc\asp.Net\words\database.dll e:\cyc\asp.Net\words\as.Net2.0news\app_code\compon.Nets\databse.cs

3、为避免每次编译的麻烦,可以建立cmd文件如csd_dl.cmd ,代码如下:
cd\
d:
cd D:\sys03\microsoft.Net\framework\v1.4322
csc /t:library /r:System.Web.dll /r:System.dll /out:E:\web\bin\WebTools.dll e:\web\bin\DbLink.cs
cmd


- 输出文件 -
/out: <file> 输出文件名(默认值: 包含主类的文件或第一个文件的基名称)
/target:exe 生成控制台可执行文件(默认) (缩写: /t:exe)
/target:winexe 生成 Windows 可执行文件 (缩写: /t:winexe)
/target:library 生成库 (缩写: /t:library)
/target:module 生成能添加到其他程序集的模块 (缩写: /t:module)
/define: <symbol list> 定义条件编译符号 (缩写: /d)
/doc: <file> 要生成的 Xml 文档文件



------解决方案--------------------------------------------------------
用.net命令编译,

编译 File.cs 以产生 File.exe:
csc File.cs
编译 File.cs 以产生 File.dll:
csc /target:library File.cs
编译 File.cs 并创建 My.exe:
csc /out:My.exe File.cs
通过使用优化和定义 DEBUG 符号,编译当前目录中所有的 C# 文件。输出为 File2.exe:
csc /define:DEBUG /optimize /out:File2.exe *.cs
编译当前目录中所有的 C# 文件,以产生 File2.dll 的调试版本。不显示任何徽标和警告:
csc /target:library /out:File2.dll /warn:0 /nologo /debug *.cs
将当前目录中所有的 C# 文件编译为 Something.xyz(一个 DLL):
csc /target:library /out:Something.xyz *.cs


如果你用的是.NET的工具,你不用设置路径,如果你用的是windows的CMD,你得设置编译器的路径

详细请查询MSDN
  相关解决方案