I would like to compile a simple console application which uses a reference from a .dll to learn how basic dynamic linking in csharp works. The main file is test.cs
:
using System;
using TestLibrary;
namespace Test
{
class Test
{
static int Main()
{
Console.WriteLine(TestLibrary.AddThreeNumbers(1,2,3));
return 0;
}
}
}
The class library is:
using System;
namespace TestLibrary
{
class TestLibrary
{
int AddThreeNumbers(int a, int b, int c)
{
return a+b+c;
}
}
}
I use the following in the powershell developer command prompt to compile library.cs
into a dll:
csc library.cs -target:library -out:library.dll
This works fine. But I then try to link to make an executable as follows:
csc test.cs -reference:TestLibrary=library.dll
But this returns an error:
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?)
Is this is a problem with my code or a problem with how I am compiling it? Any help would be much appreciated.
正如@Gusman 所说,要使用的命令是:
csc /r:library.dll /out:test.exe test.cs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.