Reputation: 5877
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.
Upvotes: 0
Views: 175
Reputation: 5877
As @Gusman said the command to use is :
csc /r:library.dll /out:test.exe test.cs
Upvotes: 1