user13094861
user13094861

Reputation:

How to reference an assembly(*.dll) without visual studio?

Goal

I'm trying to use a dll file in a c# project. I know how to it with visual studio but is there any other way (without visual studio)? When I add dll file as reference into console app with visual studio, it does not add anything to Program.cs, But I think something should be added to it (and Program.cs of dll file I guess) when you don't want to use visual studio. For example what should I do when I want to use the following dll file:

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;
        }
    }
}

in the following Console App:


using System;
using ClassLibrary1;

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

Edit

I mean what does visual studio to add a reference to project? (I want to do it without Visual Studio).

Upvotes: 1

Views: 2090

Answers (2)

Krusty
Krusty

Reputation: 1173

Add the DLL reference into the csproj file.

Like (new csproj file format):

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

Upvotes: 2

Samim Hussain
Samim Hussain

Reputation: 416

This method will load the dll as below-

var DLL=Assembly.LoadFile(YourfilePath)

Upvotes: 0

Related Questions