当您将引用(dll文件)添加到项目时,Visual Studio会发生什么变化?

问题描述 投票:0回答:2

我正在尝试在c#项目中使用* .dll文件。我知道如何使用Visual Studio,但是还有其他方法(没有Visual Studio)吗?当我将* .dll文件添加为带有Visual Studio的控制台应用程序中的引用时,它不会向Program.cs添加任何内容,但是我认为应该在您添加一些内容(以及我猜为* .dll文件的Program.cs)不想使用Visual Studio。例如,我想从dll文件导入功能Sum:

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

namespace ClassLibrary1
{
    public class Class1
    {
        public static int Sum(int x, int y)
        {
            int a = x;
            int b = y;
            int result = a + b;
            return result;
        }
    }
}

至控制台应用程序:

using System;
using ClassLibrary1;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Class1.Sum(1, 40));
        }
    }
}

编辑

我的意思是,当您添加对项目的引用时,Visual Studio会发生什么变化?

c# .net visual-studio dllimport dllexport
2个回答
1
投票

将DLL引用添加到csproj文件中。

就像(新的csproj文件格式):

<ItemGroup>
    <ProjectReference Include="..\..\*.dll" />
</ItemGroup>

0
投票

此方法将如下加载DLL-

var DLL=Assembly.LoadFile(YourfilePath)
© www.soinside.com 2019 - 2024. All rights reserved.