希望使用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?)

这是我的代码有问题还是我的编译方式有问题?任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)