Reputation:
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));
}
}
}
I mean what does visual studio to add a reference to project? (I want to do it without Visual Studio).
Upvotes: 1
Views: 2090
Reputation: 1173
Add the DLL reference into the csproj file.
Like (new csproj file format):
<ItemGroup>
<ProjectReference Include="..\..\*.dll" />
</ItemGroup>
Upvotes: 2
Reputation: 416
This method will load the dll as below-
var DLL=Assembly.LoadFile(YourfilePath)
Upvotes: 0