c# - 希望使用C#中的dll编译基本程序

标签 c# compiler-errors csc

我想编译一个简单的控制台应用程序,它使用来自.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

关于c# - 希望使用C#中的dll编译基本程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64404141/

相关文章:

c# - 通过命令行编译c#代码时如何使用引用

c# - 如何获取另一个 C# 应用程序读取的内存地址?

c# - 此搜索方法中 IComparable 和 IComparable<T> 的区别

c# - 如何在 C# 中使用 TransactionScope?

python - 用 Pandas 导入数据时卡住了错误

c++ - 尝试在终端(MacOSX)中编译两个.cpp文件(来自XCode)时的“Duplicate symbol”

.net - .NET 命令行编译器在哪里?

c# 从代码后面更改javascript变量的值

sql-server - 忽略数据库项目中的错误

c# - C# 项目的编译器命令行