I faced some issues regarding adding an external assembly (.dll
) to my .NET Core 2.0
console application on Visual Studio Code as there are little to none documentation about how you can do it.
Microsoft provides a very good tutorial about how one can add NuGet Packages
and Project to project references, but no information on how to add external dlls
.
One of the things I did miss was a clear direction on how to reference a . NET dll directly (and of course still enjoy the benefits of intellisense), basically the same thing as doing Project > Add Reference > Browse in Visual Studio. And that's it!
What you have to do is create a folder, within the solution folder for example, and reference the dlls in your projects. Any third-party dll that is in the references of a project will be copied to the bin/Debug or bin/Release folder when the project is compiled.
After some research I managed to get it working.
Open your .csproj
file
Below </PropertyGroup>
tag, add
<ItemGroup>
<Reference Include="Your dll file name">
<HintPath>Your dll file name.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<!-- You may set it to true if your dll has a specific version -->
</Reference>
</ItemGroup>
Move the dll
to the root folder of your project (where Program.cs
is)
Navigate to the root folder of your project using console/terminal and execute dotnet restore
to import all the references
Then, execute dotnet run
Do not remove the dll from your root folder. If you do, you will receive the following error:
error CS0246: The type or namespace name 'Your dll File' could not be found (are you missing a using directive or an assembly reference?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With