怎样生成dll

ssiyyy 2009-04-12 03:35:05
我在App_Code下新建了一个DataOperate.cs文件,如下。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SQLite;

namespace DataOperate
{
public class Class1
{

}
}
怎样才能编译出DataOperate.dll
初学
...全文
340 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
辰爸 2009-04-12
  • 打赏
  • 举报
回复
手动把asp.net的类生成dll文件的方法 楼主可以去看看http://hi.baidu.com/farisnear/blog/item/fad141131c22fad7f7039e2f.html
wuyq11 2009-04-12
  • 打赏
  • 举报
回复
在web下建新新项目DataOperate ,为类库再编译就可
walkghost 2009-04-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jijunwu 的回复:]
新建类库文件。。。
生成就可以了
[/Quote]
UP!
ssiyyy 2009-04-12
  • 打赏
  • 举报
回复
谢谢你这么详细的回答,可是我的是在bs模式下
zzxap 2009-04-12
  • 打赏
  • 举报
回复
[code=C#]
1新建一个类库
或者编译的时候这样 csc /target:library File.cs
2在你的项目里添加引用这个DLL,然后再using ...
或者编译时这样 csc /lib:[Directory] /reference:[FileName] File.cs

我们创建以下C#代码文件:
1、 MySwap.cs
using System;
namespace MyMethods
{
public class SwapClass
{
public static bool Swap(ref long i,ref long j)
{
i = i+j;
j = i-j;
i = i-j;
return true;
}
}
}
2、 MyMaxCD.cs
using System;
namespace MyMethods
{
public class MaxCDClass
{
public static long MaxCD(long i, long j)
{
long a,b,temp;
if(i>j)
{
a = i;
b = j;
}
else
{
b = i;
a = j;
}
temp = a % b;
while(temp!=0)
{
a = b;
b = temp;
temp = a % b;
}
return b;
}
}
}
}

CSC.EXE运行:csc /target:library /out:MyDLL.DLL MySwap.cs MyMaxCD.cs完成后可在本目录下面找到我们刚才生成的MyDLL.DLL文件/target:library 编译器选项通知编译器输出 DLL 文件而不是 EXE 文件。后跟文件名的 /out 编译器选项用于指定 DLL 文件名。如果/out后面不跟文件名编译器使用第一个文件 (MySwap.cs) 作为 DLL 文件名。生成的文件为MySwap.DLL文件。

建立:MyClient.cs 文件:
using MyMethods;
class MyClient
{
public static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage: MyClient <num1> <num2>");
return;
}
long num1 = long.Parse(args[0]);
long num2 = long.Parse(args[1]);
SwapClass.Swap(ref num1,ref num2);
// 请注意,文件开头的 using 指令使您得以在编译时使用未限定的类名来引用 DLL 方法
Console.WriteLine("The result of swap is num1 = {0} and num2 ={1}",num1, num2);
long maxcd = MaxCDClass.MaxCD(num1,num2);
Console.WriteLine("The MaxCD of {0} and {1} is {2}",num1, num2, maxcd);
}
}


若要生成可执行文件 MyClient.exe,请使用以下命令行:

csc /out:MyClient.exe /reference:MyLibrary.DLL MyClient.cs

/out 编译器选项通知编译器输出 EXE 文件并且指定输出文件名 (MyClient.exe)。/reference 编译器选项指定该程序所引用的 DLL 文件。
若要运行程序,请输入 EXE 文件的名称,文件名的后面跟两个数字,例如:

MyClient 123 456

[/CODE]
  • 打赏
  • 举报
回复
新建类库文件。。。
生成就可以了

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧