如何解决希望使用C#中的dll编译基本程序
我想编译一个简单的控制台应用程序,该应用程序使用来自.dll的引用来了解csharp中基本的动态链接是如何工作的。主文件是test.cs
:
using System;
using TestLibrary;
namespace Test
{
class Test
{
static int Main()
{
Console.WriteLine(TestLibrary.AddThreeNumbers(1,2,3));
return 0;
}
}
}
类库是:
using System;
namespace TestLibrary
{
class TestLibrary
{
int AddThreeNumbers(int a,int b,int c)
{
return a+b+c;
}
}
}
我在powershell开发人员命令提示符中使用以下命令将library.cs
编译为dll:
csc library.cs -target:library -out:library.dll
这很好。但是,然后我尝试链接以使可执行文件如下所示:
csc test.cs -reference:TestLibrary=library.dll
但这会返回错误:
test.cs(2,7): error CS0246: The type or namespace name 'TestLibrary' could not be found (are you missing a using directive or an assembly reference?)
这是我的代码有问题还是我的编译方式有问题?任何帮助将不胜感激。
解决方法
@Gusman所说的要使用的命令是:
csc /r:library.dll /out:test.exe test.cs
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。