C#项目添加dll引用,调用其它项目

目录

首先,把两个项目放在同一个解决方案中

然后,生成项目BBB的dll

其次,项目AAA添加引用

代码注意事项

提醒:

项目BBB生成dll后,你对BBB进行修改,dll也会随之改变,

也就是说对BBB修改之后,也不用重新生成dll了


首先,把两个项目放在同一个解决方案中

例如:启动项目AAA,待引用项目BBB

启动项目AAA代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BBB;
namespace AAA
{
    class Program
    {
        static void Main(string[] args)
        {
            function f = new function(1,2);
            f.printf();
        }
    }
}

待引用项目BBB代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BBB
{
    
    public class function
    {
        public int a, b;
        public function(int a,int b)
        {
            this.a = a;
            this.b = b;
        }
        public void printf()
        {
            Console.Write(a + b);
            Console.ReadKey();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            
        }
    }
}

然后,生成项目BBB的dll

右击项目BBB,在出现菜单中,点击生成

其次,项目AAA添加引用

在项目AAA中添加引用,即BBB生成的dll

添加引用结果:

代码注意事项

提醒:

项目BBB生成dll后,你对BBB进行修改,dll也会随之改变,

也就是说对BBB修改之后,也不用重新生成dll了

猜你喜欢

转载自blog.csdn.net/qq_41664159/article/details/101701660